1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
5 <manualpage metafile="bind.xml.meta">
10 <p>Configuring Apache to listen on specific addresses and ports.</p>
13 <seealso><a href="vhosts/">Virtual Hosts</a></seealso>
14 <seealso><a href="dns-caveats.html">DNS Issues</a></seealso>
16 <section id="overview">
17 <title>Overview</title>
22 <module>mpm_common</module>
25 <directive module="core">VirtualHost</directive>
26 <directive module="mpm_common">Listen</directive>
31 <p>When Apache starts, it binds to some port and address on
32 the local machine and waits for incoming requests. By default,
33 it listens to all addresses on the machine. However, it needs to
34 be told to listen on specific ports, or to listen on only selected
35 addresses, or a combination. This is often combined with the
36 Virtual Host feature which determines how Apache responds to
37 different IP addresses, hostnames and ports.</p>
39 <p>The <directive module="mpm_common">Listen</directive>
40 directive tells the server to accept
41 incoming requests only on the specified port or
42 address-and-port combinations. If only a port number is
43 specified in the <directive module="mpm_common">Listen</directive>
45 listens to the given port on all interfaces. If an IP address
46 is given as well as a port, the server will listen on the given
47 port and interface. Multiple Listen directives may be used to
48 specify a number of addresses and ports to listen on. The
49 server will respond to requests from any of the listed
50 addresses and ports.</p>
52 <p>For example, to make the server accept connections on both
53 port 80 and port 8000, use:</p>
60 <p>To make the server accept connections on two specified
61 interfaces and port numbers, use</p>
64 Listen 192.170.2.1:80<br />
65 Listen 192.170.2.5:8000
68 <p>IPv6 addresses must be surrounded in square brackets, as in the
69 following example:</p>
72 Listen [fe80::a00:20ff:fea7:ccea]:80
77 <title>Special IPv6 Considerations</title>
79 <p>A growing number of platforms implement IPv6, and APR supports
80 IPv6 on most of these platforms, allowing Apache to allocate IPv6
81 sockets and handle requests which were sent over IPv6.</p>
83 <p>One complicating factor for Apache administrators is whether or
84 not an IPv6 socket can handle both IPv4 connections and IPv6
85 connections. Handling IPv4 connections with an IPv6 socket uses
86 IPv4-mapped IPv6 addresses, which are allowed by default on most
87 platforms but are disallowed by default on FreeBSD, NetBSD, and
88 OpenBSD in order to match the system-wide policy on those
89 platforms. But even on systems where it is disallowed by default, a
90 special configure parameter can change this behavior for Apache.</p>
92 <p>If you want Apache to handle IPv4 and IPv6 connections with a
93 minimum of sockets, which requires using IPv4-mapped IPv6 addresses,
94 specify the <code>--enable-v4-mapped</code> configure option and use
95 generic Listen directives like the following:</p>
101 <p>With <code>--enable-v4-mapped</code>, the Listen directives in the
102 default configuration file created by Apache will use this form.
103 <code>--enable-v4-mapped</code> is the default on all platforms but
104 FreeBSD, NetBSD, and OpenBSD, so this is probably how your Apache was
107 <p>If you want Apache to handle IPv4 connections only, regardless of
108 what your platform and APR will support, specify an IPv4 address on all
109 Listen directives, as in the following examples:</p>
112 Listen 0.0.0.0:80<br />
113 Listen 192.170.2.1:80
116 <p>If you want Apache to handle IPv4 and IPv6 connections on separate
117 sockets (i.e., to disable IPv4-mapped addresses), specify the
118 <code>--disable-v4-mapped</code> configure option and use specific Listen
119 directives like the following:</p>
126 <p>With <code>--disable-v4-mapped</code>, the Listen directives in the
127 default configuration file created by Apache will use this form.
128 <code>--disable-v4-mapped</code> is the default on FreeBSD, NetBSD, and
133 <section id="virtualhost">
134 <title>How This Works With Virtual Hosts</title>
136 <p>Listen does not implement Virtual Hosts. It only tells the
137 main server what addresses and ports to listen to. If no
138 <directive module="core" type="section">VirtualHost</directive>
139 directives are used, the server will behave
140 the same for all accepted requests. However,
141 <directive module="core" type="section">VirtualHost</directive>
142 can be used to specify a different behavior
143 for one or more of the addresses and ports. To implement a
144 VirtualHost, the server must first be told to listen to the
145 address and port to be used. Then a
146 <directive module="core" type="section">VirtualHost</directive> section
147 should be created for a specified address and port to set the
148 behavior of this virtual host. Note that if the
149 <directive module="core" type="section">VirtualHost</directive>
150 is set for an address and port that the
151 server is not listening to, it cannot be accessed.</p>