458N/A<
title>Setting which addresses and ports Apache uses</
title>
458N/A<
h1>Setting which addresses and ports Apache uses</
h1>
458N/AWhen Apache starts, it connects to some port and address on the
458N/Alocal machine and waits for incoming requests. By default, it
458N/Alistens to all addresses on the machine, and to the port
458N/Aas specified by the <
tt>Port</
tt> directive in the server configuration.
458N/AHowever, it can be told to listen to more the one port, or to listen
458N/Ato only selected addresses, or a combination. This is often combined
458N/Awith the Virtual Host feature which determines how Apache
458N/Aresponds to different IP addresses, hostnames and ports.<
p>
458N/AThere are two directives used to restrict or specify which addresses
458N/Aand ports Apache listens to.
458N/A<
li><
a href="#bindaddress">BindAddress</
a> is used to restrict the server to listening to
458N/A a single address, and can be used to permit multiple Apache servers
458N/A on the same machine listening to different IP addresses.
458N/A<
li><
a href="#listen">Listen</
a> can be used to make a single Apache server listen
618N/A<
h3><
a name="bindaddress">BindAddress</
a></
h3>
458N/A<
strong>Syntax:</
strong> BindAddress <
em>[ * | IP-address | hostname ]</
em><
br>
458N/A<
strong>Default:</
strong> <
code>BindAddress *</
code><
br>
844N/A<
strong>Context:</
strong> server config<
br>
952N/A<
strong>Status:</
strong> Core<
p>
1273N/AMakes the server listen to just the specified address. If the argument
458N/Ais *, the server listens to all addresses. The port listened to
458N/Ais set with the <
tt>Port</
tt> directive. Only one BindAddress
581N/A<
h3><
a name="listen">Listen</
a></
h3>
458N/A<
strong>Syntax:</
strong> Listen <
em>[ port | IP-address:port ]</
em><
br>
458N/A<
strong>Default:</
strong> <
code>none</
code><
br>
458N/A<
strong>Context:</
strong> server config<
br>
458N/A<
strong>Status:</
strong> Core<
p>
969N/A<
tt>Listen</
tt> can be used instead of <
tt>BindAddress</
tt> and
969N/A<
tt>Port</
tt>. It tells the server to accept incoming requests on the
969N/Aspecified port or address-and-port combination. If the first format is
969N/Aused, with a port number only, the server listens to the given port on
969N/Aall interfaces, instead of the port given by the <
tt>Port</
tt>
969N/Adirective. If an IP address is given as well as a port, the server
969N/Awill listen on the given port and interface. <
p> Multiple Listen
458N/Adirectives may be used to specify a number of addresses and ports to
458N/Alisten to. The server will respond to requests from any of the listed
458N/AFor example, to make the server accept connections on both port
458N/ATo make the server accept connections on two specified
458N/Ainterfaces and port numbers, use
646N/A Listen 192.170.2.5:8000
646N/A<
h2>How this works with Virtual Hosts</
h2>
646N/ABindAddress and Listen do not implement Virtual Hosts. They tell the
814N/Amain server what addresses and ports to listen to. If no
814N/A<VirtualHost> directives are used, the server will behave the
814N/Asame for all accepted requests. However, <VirtualHost> can be
814N/Aused to specify a different behavour for one or more of the addresses
814N/Aand ports. To implement a VirtualHost, the server must first be told
814N/Ato listen to the address and port to be used. Then a
646N/A<VirtualHost> section should be created for a specified address
646N/Aand port to set the behavior of this virtual host. Note that if the
646N/A<VirtualHost> is set for an address and port that the server is
646N/Anot listening to, it cannot be accessed.
458N/ASee also the documentation on