2 <title>Setting which addresses and ports Apache uses</title>
5 <!--#include virtual="header.html" -->
6 <h1>Setting which addresses and ports Apache uses</h1>
10 When Apache starts, it connects to some port and address on the
11 local machine and waits for incoming requests. By default, it
12 listens to all addresses on the machine, and to the port
13 as specified by the <tt>Port</tt> directive in the server configuration.
14 However, it can be told to listen to more the one port, or to listen
15 to only selected addresses, or a combination. This is often combined
16 with the Virtual Host feature which determines how Apache
17 responds to different IP addresses, hostnames and ports.<p>
19 There are two directives used to restrict or specify which addresses
20 and ports Apache listens to.
23 <li><a href="#bindaddress">BindAddress</a> is used to restrict the server to listening to
24 a single address, and can be used to permit multiple Apache servers
25 on the same machine listening to different IP addresses.
26 <li><a href="#listen">Listen</a> can be used to make a single Apache server listen
27 to more than one address and/or port.
30 <h3><a name="bindaddress">BindAddress</a></h3>
31 <strong>Syntax:</strong> BindAddress <em>[ * | IP-address | hostname ]</em><br>
32 <strong>Default:</strong> <code>BindAddress *</code><br>
33 <strong>Context:</strong> server config<br>
34 <strong>Status:</strong> Core<p>
36 Makes the server listen to just the specified address. If the argument
37 is *, the server listens to all addresses. The port listened to
38 is set with the <tt>Port</tt> directive. Only one BindAddress
41 <h3><a name="listen">Listen</a></h3>
42 <strong>Syntax:</strong> Listen <em>[ port | IP-address:port ]</em><br>
43 <strong>Default:</strong> <code>none</code><br>
44 <strong>Context:</strong> server config<br>
45 <strong>Status:</strong> Core<p>
47 <tt>Listen</tt> can be used instead of <tt>BindAddress</tt> and
48 <tt>Port</tt>. It tells the server to accept incoming requests on the
49 specified port or address-and-port combination. If the first format is
50 used, with a port number only, the server listens to the given port on
51 all interfaces, instead of the port given by the <tt>Port</tt>
52 directive. If an IP address is given as well as a port, the server
53 will listen on the given port and interface. <p> Multiple Listen
54 directives may be used to specify a number of addresses and ports to
55 listen to. The server will respond to requests from any of the listed
56 addresses and ports.<p>
58 For example, to make the server accept connections on both port
59 80 and port 8000, use:
65 To make the server accept connections on two specified
66 interfaces and port numbers, use
69 Listen 192.170.2.5:8000
72 <h2>How this works with Virtual Hosts</h2>
74 BindAddress and Listen do not implement Virtual Hosts. They tell the
75 main server what addresses and ports to listen to. If no
76 <VirtualHost> directives are used, the server will behave the
77 same for all accepted requests. However, <VirtualHost> can be
78 used to specify a different behavour for one or more of the addresses
79 and ports. To implement a VirtualHost, the server must first be told
80 to listen to the address and port to be used. Then a
81 <VirtualHost> section should be created for a specified address
82 and port to set the behaviour of this virtual host. Note that if the
83 <VirtualHost> is set for an address and port that the server is
84 not listening to, it cannot be accessed.
88 See also the documentation on
89 <a href="virtual-host.html">Virtual Hosts</a>,
90 <a href="host.html">Non-IP virtual hosts</a>,
91 <a href="core.html#bindaddress">BindAddress directive</a>,
92 <a href="core.html#port">Port directive</a>
94 <a href="core.html#virtualhost"><VirtualHost> section</a>.
97 <!--#include virtual="footer.html" -->