bind.html revision f9b3be308809978f797e0c57b296147532a4313c
0N/A<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
797N/A<HTML><HEAD>
0N/A<TITLE>Setting which addresses and ports Apache uses</TITLE>
0N/A</HEAD>
0N/A
0N/A<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
0N/A<BODY
0N/A BGCOLOR="#FFFFFF"
0N/A TEXT="#000000"
0N/A LINK="#0000FF"
0N/A VLINK="#000080"
0N/A ALINK="#FF0000"
0N/A>
0N/A<!--#include virtual="header.html" -->
0N/A<h1 ALIGN="CENTER">Setting which addresses and ports Apache uses</H1>
0N/A
0N/A<HR>
0N/A
553N/AWhen Apache starts, it connects to some port and address on the
553N/Alocal machine and waits for incoming requests. By default, it
553N/Alistens to all addresses on the machine, and to the port
0N/Aas specified by the <TT>Port</TT> directive in the server configuration.
0N/AHowever, it can be told to listen to more the one port, or to listen
0N/Ato only selected addresses, or a combination. This is often combined
0N/Awith the Virtual Host feature which determines how Apache
0N/Aresponds to different IP addresses, hostnames and ports.<P>
0N/A
0N/AThere are two directives used to restrict or specify which addresses
0N/Aand ports Apache listens to.
288N/A
0N/A<UL>
0N/A<LI><A HREF="#bindaddress">BindAddress</A> is used to restrict the server to listening to
513N/A a single address, and can be used to permit multiple Apache servers
0N/A on the same machine listening to different IP addresses.
0N/A<LI><A HREF="#listen">Listen</A> can be used to make a single Apache server listen
0N/A to more than one address and/or port.
0N/A</UL>
0N/A
0N/A<h3><A name="bindaddress">BindAddress</A></h3>
0N/A<STRONG>Syntax:</STRONG> BindAddress <EM>[ * | IP-address | hostname ]</EM><BR>
0N/A<STRONG>Default:</STRONG> <CODE>BindAddress *</CODE><BR>
0N/A<STRONG>Context:</STRONG> server config<BR>
0N/A<STRONG>Status:</STRONG> Core<P>
0N/A
0N/AMakes the server listen to just the specified address. If the argument
0N/Ais *, the server listens to all addresses. The port listened to
0N/Ais set with the <TT>Port</TT> directive. Only one BindAddress
0N/Ashould be used.
0N/A
0N/A<h3><A name="listen">Listen</A></h3>
0N/A<STRONG>Syntax:</STRONG> Listen <EM>[ port | IP-address:port ]</EM><BR>
0N/A<STRONG>Default:</STRONG> <CODE>none</CODE><BR>
<STRONG>Context:</STRONG> server config<BR>
<STRONG>Status:</STRONG> Core<P>
<TT>Listen</TT> can be used instead of <TT>BindAddress</TT> and
<TT>Port</TT>. It tells the server to accept incoming requests on the
specified port or address-and-port combination. If the first format is
used, with a port number only, the server listens to the given port on
all interfaces, instead of the port given by the <TT>Port</TT>
directive. If an IP address is given as well as a port, the server
will listen on the given port and interface. <P> Multiple Listen
directives may be used to specify a number of addresses and ports to
listen to. The server will respond to requests from any of the listed
addresses and ports.<P>
For example, to make the server accept connections on both port
80 and port 8000, use:
<PRE>
Listen 80
Listen 8000
</PRE>
To make the server accept connections on two specified
interfaces and port numbers, use
<PRE>
Listen 192.170.2.1:80
Listen 192.170.2.5:8000
</PRE>
<h2>How this works with Virtual Hosts</h2>
BindAddress and Listen do not implement Virtual Hosts. They tell the
main server what addresses and ports to listen to. If no
&lt;VirtualHost&gt; directives are used, the server will behave the
same for all accepted requests. However, &lt;VirtualHost&gt; can be
used to specify a different behavior for one or more of the addresses
and ports. To implement a VirtualHost, the server must first be told
to listen to the address and port to be used. Then a
&lt;VirtualHost&gt; section should be created for a specified address
and port to set the behavior of this virtual host. Note that if the
&lt;VirtualHost&gt; is set for an address and port that the server is
not listening to, it cannot be accessed.
<h2>See also</h2>
See also the documentation on
<A HREF="vhosts/index.html">Virtual Hosts</A>,
<A HREF="mod/core.html#bindaddress">BindAddress directive</A>,
<A HREF="mod/core.html#port">Port directive</A>,
<A HREF="dns-caveats.html">DNS Issues</A>
and
<A HREF="mod/core.html#virtualhost">&lt;VirtualHost&gt; section</A>.
<!--#include virtual="footer.html" -->
</BODY>
</HTML>