1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
3 <title>Setting which addresses and ports Apache uses</title>
6 <BODY BGCOLOR="white" TEXT="black" LINK="blue" VLINK="navy" ALINK="red">
7 <!--#include virtual="header.html" -->
8 <h1 ALIGN="CENTER">Setting which addresses and ports Apache uses</h1>
12 When Apache starts, it connects to some port and address on the
13 local machine and waits for incoming requests. By default, it
14 listens to all addresses on the machine, and to the port
15 as specified by the <tt>Port</tt> directive in the server configuration.
16 However, it can be told to listen to more the one port, or to listen
17 to only selected addresses, or a combination. This is often combined
18 with the Virtual Host feature which determines how Apache
19 responds to different IP addresses, hostnames and ports.<p>
21 There are two directives used to restrict or specify which addresses
22 and ports Apache listens to.
25 <li><a href="#bindaddress">BindAddress</a> is used to restrict the server to listening to
26 a single address, and can be used to permit multiple Apache servers
27 on the same machine listening to different IP addresses.
28 <li><a href="#listen">Listen</a> can be used to make a single Apache server listen
29 to more than one address and/or port.
32 <h3><a name="bindaddress">BindAddress</a></h3>
33 <strong>Syntax:</strong> BindAddress <em>[ * | IP-address | hostname ]</em><br>
34 <strong>Default:</strong> <code>BindAddress *</code><br>
35 <strong>Context:</strong> server config<br>
36 <strong>Status:</strong> Core<p>
38 Makes the server listen to just the specified address. If the argument
39 is *, the server listens to all addresses. The port listened to
40 is set with the <tt>Port</tt> directive. Only one BindAddress
43 <h3><a name="listen">Listen</a></h3>
44 <strong>Syntax:</strong> Listen <em>[ port | IP-address:port ]</em><br>
45 <strong>Default:</strong> <code>none</code><br>
46 <strong>Context:</strong> server config<br>
47 <strong>Status:</strong> Core<p>
49 <tt>Listen</tt> can be used instead of <tt>BindAddress</tt> and
50 <tt>Port</tt>. It tells the server to accept incoming requests on the
51 specified port or address-and-port combination. If the first format is
52 used, with a port number only, the server listens to the given port on
53 all interfaces, instead of the port given by the <tt>Port</tt>
54 directive. If an IP address is given as well as a port, the server
55 will listen on the given port and interface. <p> Multiple Listen
56 directives may be used to specify a number of addresses and ports to
57 listen to. The server will respond to requests from any of the listed
58 addresses and ports.<p>
60 For example, to make the server accept connections on both port
61 80 and port 8000, use:
67 To make the server accept connections on two specified
68 interfaces and port numbers, use
71 Listen 192.170.2.5:8000
74 <h2>How this works with Virtual Hosts</h2>
76 BindAddress and Listen do not implement Virtual Hosts. They tell the
77 main server what addresses and ports to listen to. If no
78 <VirtualHost> directives are used, the server will behave the
79 same for all accepted requests. However, <VirtualHost> can be
80 used to specify a different behavior for one or more of the addresses
81 and ports. To implement a VirtualHost, the server must first be told
82 to listen to the address and port to be used. Then a
83 <VirtualHost> section should be created for a specified address
84 and port to set the behavior of this virtual host. Note that if the
85 <VirtualHost> is set for an address and port that the server is
86 not listening to, it cannot be accessed.
90 See also the documentation on
91 <a href="virtual-host.html">Virtual Hosts</a>,
92 <a href="host.html">Non-IP virtual hosts</a>,
93 <a href="mod/core.html#bindaddress">BindAddress directive</a>,
94 <a href="mod/core.html#port">Port directive</a>,
95 <a href="dns-caveats.html">DNS Issues</a>
97 <a href="mod/core.html#virtualhost"><VirtualHost> section</a>.
99 <!--#include virtual="footer.html" -->