1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
3 <TITLE>Setting which addresses and ports Apache uses</TITLE>
6 <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
14 <!--#include virtual="header.html" -->
15 <h1 ALIGN="CENTER">Setting which addresses and ports Apache uses</H1>
19 When Apache starts, it connects to some port and address on the
20 local machine and waits for incoming requests. By default, it
21 listens to all addresses on the machine, and to the port
22 as specified by the <TT>Port</TT> directive in the server configuration.
23 However, it can be told to listen to more the one port, or to listen
24 to only selected addresses, or a combination. This is often combined
25 with the Virtual Host feature which determines how Apache
26 responds to different IP addresses, hostnames and ports.<P>
28 There are two directives used to restrict or specify which addresses
29 and ports Apache listens to.
32 <LI><A HREF="#bindaddress">BindAddress</A> is used to restrict the server to listening to
33 a single address, and can be used to permit multiple Apache servers
34 on the same machine listening to different IP addresses.
35 <LI><A HREF="#listen">Listen</A> can be used to make a single Apache server listen
36 to more than one address and/or port.
39 <h3><A name="bindaddress">BindAddress</A></h3>
41 HREF="directive-dict.html#Syntax"
43 ><STRONG>Syntax:</STRONG></A> BindAddress <EM>[ * | IP-address | hostname ]</EM><BR>
45 HREF="directive-dict.html#Default"
47 ><STRONG>Default:</STRONG></A> <CODE>BindAddress *</CODE><BR>
49 HREF="directive-dict.html#Context"
51 ><STRONG>Context:</STRONG></A> server config<BR>
53 HREF="directive-dict.html#Status"
55 ><STRONG>Status:</STRONG></A> Core<P>
57 Makes the server listen to just the specified address. If the argument
58 is *, the server listens to all addresses. The port listened to
59 is set with the <TT>Port</TT> directive. Only one BindAddress
62 <h3><A name="listen">Listen</A></h3>
64 HREF="directive-dict.html#Syntax"
66 ><STRONG>Syntax:</STRONG></A> Listen <EM>[ port | IP-address:port ]</EM><BR>
68 HREF="directive-dict.html#Default"
70 ><STRONG>Default:</STRONG></A> <CODE>none</CODE><BR>
72 HREF="directive-dict.html#Context"
74 ><STRONG>Context:</STRONG></A> server config<BR>
76 HREF="directive-dict.html#Status"
78 ><STRONG>Status:</STRONG></A> Core<P>
80 <TT>Listen</TT> can be used instead of <TT>BindAddress</TT> and
81 <TT>Port</TT>. It tells the server to accept incoming requests on the
82 specified port or address-and-port combination. If the first format is
83 used, with a port number only, the server listens to the given port on
84 all interfaces, instead of the port given by the <TT>Port</TT>
85 directive. If an IP address is given as well as a port, the server
86 will listen on the given port and interface. <P> Multiple Listen
87 directives may be used to specify a number of addresses and ports to
88 listen to. The server will respond to requests from any of the listed
89 addresses and ports.<P>
91 For example, to make the server accept connections on both port
92 80 and port 8000, use:
98 To make the server accept connections on two specified
99 interfaces and port numbers, use
101 Listen 192.170.2.1:80
102 Listen 192.170.2.5:8000
105 <h2>How this works with Virtual Hosts</h2>
107 BindAddress and Listen do not implement Virtual Hosts. They tell the
108 main server what addresses and ports to listen to. If no
109 <VirtualHost> directives are used, the server will behave the
110 same for all accepted requests. However, <VirtualHost> can be
111 used to specify a different behavior for one or more of the addresses
112 and ports. To implement a VirtualHost, the server must first be told
113 to listen to the address and port to be used. Then a
114 <VirtualHost> section should be created for a specified address
115 and port to set the behavior of this virtual host. Note that if the
116 <VirtualHost> is set for an address and port that the server is
117 not listening to, it cannot be accessed.
121 See also the documentation on
122 <A HREF="vhosts/index.html">Virtual Hosts</A>,
123 <A HREF="mod/core.html#bindaddress">BindAddress directive</A>,
124 <A HREF="mod/core.html#port">Port directive</A>,
125 <A HREF="dns-caveats.html">DNS Issues</A>
127 <A HREF="mod/core.html#virtualhost"><VirtualHost> section</A>.
129 <!--#include virtual="footer.html" -->