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>
17 <p>When Apache starts, it connects to some port and address on the
18 local machine and waits for incoming requests. By default, it
19 listens to all addresses on the machine, and to the port
20 as specified by the <code>Port</code> directive in the server configuration.
21 However, it can be told to listen to more the one port, or to listen
22 to only selected addresses, or a combination. This is often combined
23 with the Virtual Host feature which determines how Apache
24 responds to different IP addresses, hostnames and ports.</p>
26 <p>The <code>Listen</code> directive tells the server to accept
27 incoming requests only on the specified port or address-and-port
28 combinations. If only a port number is specified in the
29 <code>Listen</code> directive, the server listens to the given port on
30 all interfaces, instead of the port given by the <code>Port</code>
31 directive. If an IP address is given as well as a port, the server
32 will listen on the given port and interface. Multiple Listen
33 directives may be used to specify a number of addresses and ports to
34 listen to. The server will respond to requests from any of the listed
35 addresses and ports.</P>
37 <p>For example, to make the server accept connections on both port
38 80 and port 8000, use:
44 To make the server accept connections on two specified
45 interfaces and port numbers, use
48 Listen 192.170.2.5:8000
51 <H2>How this works with Virtual Hosts</H2>
53 <p>Listen does not implement Virtual Hosts. It only tells the
54 main server what addresses and ports to listen to. If no
55 <VirtualHost> directives are used, the server will behave the
56 same for all accepted requests. However, <VirtualHost> can be
57 used to specify a different behavior for one or more of the addresses
58 and ports. To implement a VirtualHost, the server must first be told
59 to listen to the address and port to be used. Then a
60 <VirtualHost> section should be created for a specified address
61 and port to set the behavior of this virtual host. Note that if the
62 <VirtualHost> is set for an address and port that the server is
63 not listening to, it cannot be accessed.
67 See also the documentation on
68 <a href="mod/mpm_common.html#listen">Listen directive</a>,
69 <A HREF="vhosts/index.html">Virtual Hosts</A>,
70 <A HREF="mod/core.html#port">Port directive</A>,
71 <A HREF="dns-caveats.html">DNS Issues</A>
73 <A HREF="mod/core.html#virtualhost"><VirtualHost> section</A>.
75 <!--#include virtual="footer.html" -->