0N/A<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
0N/A<
TITLE>Setting which addresses and ports Apache uses</
TITLE>
0N/A<!-- Background white, links blue (unvisited), navy (visited), red (active) --> 0N/A<
h1 ALIGN="CENTER">Setting which addresses and ports Apache uses</
H1>
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/AThere are two directives used to restrict or specify which addresses
0N/Aand ports Apache listens to.
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<
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/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/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
For example, to make the server accept connections on both port
To make the server accept connections on two specified
interfaces and port numbers, use
<
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
<VirtualHost> directives are used, the server will behave the
same for all accepted requests. However, <VirtualHost> 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
<VirtualHost> section should be created for a specified address
and port to set the behavior of this virtual host. Note that if the
<VirtualHost> is set for an address and port that the server is
not listening to, it cannot be accessed.
See also the documentation on
<
A HREF="mod/core.html#bindaddress">BindAddress directive</
A>,
<
A HREF="mod/core.html#virtualhost"><VirtualHost> section</
A>.