299N/A<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
299N/A<
TITLE>Setting which addresses and ports Apache uses</
TITLE>
299N/A<!-- Background white, links blue (unvisited), navy (visited), red (active) --> 299N/A<
h1 ALIGN="CENTER">Setting which addresses and ports Apache uses</
H1>
873N/AWhen Apache starts, it connects to some port and address on the
299N/Alocal machine and waits for incoming requests. By default, it
299N/Alistens to all addresses on the machine, and to the port
299N/Aas specified by the <
TT>Port</
TT> directive in the server configuration.
299N/AHowever, it can be told to listen to more the one port, or to listen
299N/Ato only selected addresses, or a combination. This is often combined
3232N/Awith the Virtual Host feature which determines how Apache
299N/Aresponds to different IP addresses, hostnames and ports.<
P>
299N/AThere are two directives used to restrict or specify which addresses
1242N/Aand ports Apache listens to.
299N/A<
LI><
A HREF="#bindaddress">BindAddress</
A> is used to restrict the server to listening to
299N/A a single address, and can be used to permit multiple Apache servers
299N/A on the same machine listening to different IP addresses.
299N/A<
LI><
A HREF="#listen">Listen</
A> can be used to make a single Apache server listen
299N/A<
h3><
A name="bindaddress">BindAddress</
A></
h3>
299N/A<
STRONG>Syntax:</
STRONG> BindAddress <
EM>[ * | IP-address | hostname ]</
EM><
BR>
299N/A<
STRONG>Default:</
STRONG> <
CODE>BindAddress *</
CODE><
BR>
299N/A<
STRONG>Context:</
STRONG> server config<
BR>
299N/A<
STRONG>Status:</
STRONG> Core<
P>
299N/AMakes the server listen to just the specified address. If the argument
299N/Ais *, the server listens to all addresses. The port listened to
299N/Ais set with the <
TT>Port</
TT> directive. Only one BindAddress
299N/A<
h3><
A name="listen">Listen</
A></
h3>
299N/A<
STRONG>Syntax:</
STRONG> Listen <
EM>[ port | IP-address:port ]</
EM><
BR>
299N/A<
STRONG>Default:</
STRONG> <
CODE>none</
CODE><
BR>
299N/A<
STRONG>Context:</
STRONG> server config<
BR>
299N/A<
STRONG>Status:</
STRONG> Core<
P>
299N/A<
TT>Listen</
TT> can be used instead of <
TT>BindAddress</
TT> and
2334N/A<
TT>Port</
TT>. It tells the server to accept incoming requests on the
299N/Aspecified port or address-and-port combination. If the first format is
299N/Aused, with a port number only, the server listens to the given port on
299N/Aall interfaces, instead of the port given by the <
TT>Port</
TT>
299N/Adirective. If an IP address is given as well as a port, the server
299N/Awill listen on the given port and interface. <
P> Multiple Listen
299N/Adirectives may be used to specify a number of addresses and ports to
299N/Alisten to. The server will respond to requests from any of the listed
299N/AFor example, to make the server accept connections on both port
299N/ATo make the server accept connections on two specified
2334N/Ainterfaces and port numbers, use
299N/A Listen 192.170.2.5:8000
1242N/A<
h2>How this works with Virtual Hosts</
h2>
1242N/ABindAddress and Listen do not implement Virtual Hosts. They tell the
1242N/Amain server what addresses and ports to listen to. If no
1242N/A<VirtualHost> directives are used, the server will behave the
1242N/Asame for all accepted requests. However, <VirtualHost> can be
2334N/Aused to specify a different behavior for one or more of the addresses
299N/Aand ports. To implement a VirtualHost, the server must first be told
299N/Ato listen to the address and port to be used. Then a
2334N/A<VirtualHost> section should be created for a specified address
299N/Aand port to set the behavior of this virtual host. Note that if the
299N/A<VirtualHost> is set for an address and port that the server is
299N/Anot listening to, it cannot be accessed.
299N/ASee also the documentation on