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">
6 <relativepath href="."/>
11 <p>Configuring Apache to listen on specific addresses and ports.</p>
14 <seealso><a href="vhosts/">Virtual Hosts</a></seealso>
15 <seealso><a href="dns-caveats.html">DNS Issues</a></seealso>
17 <section id="overview">
18 <title>Overview</title>
23 <module>mpm_common</module>
26 <directive module="core">VirtualHost</directive>
27 <directive module="mpm_common">Listen</directive>
32 <p>When Apache starts, it binds to some port and address on
33 the local machine and waits for incoming requests. By default,
34 it listens to all addresses on the machine. However, it needs to
35 be told to listen on specific ports, or to listen on only selected
36 addresses, or a combination. This is often combined with the
37 Virtual Host feature which determines how Apache responds to
38 different IP addresses, hostnames and ports.</p>
40 <p>The <directive module="mpm_common">Listen</directive>
41 directive tells the server to accept
42 incoming requests only on the specified port or
43 address-and-port combinations. If only a port number is
44 specified in the <directive module="mpm_common">Listen</directive>
46 listens to the given port on all interfaces. If an IP address
47 is given as well as a port, the server will listen on the given
48 port and interface. Multiple Listen directives may be used to
49 specify a number of addresses and ports to listen on. The
50 server will respond to requests from any of the listed
51 addresses and ports.</p>
53 <p>For example, to make the server accept connections on both
54 port 80 and port 8000, use:</p>
61 <p>To make the server accept connections on two specified
62 interfaces and port numbers, use</p>
65 Listen 192.170.2.1:80<br />
66 Listen 192.170.2.5:8000
69 <p>IPv6 addresses must be surrounded in square brackets, as in the
70 following example:</p>
73 Listen [fe80::a00:20ff:fea7:ccea]:80
78 <title>Special IPv6 Considerations</title>
80 <p>A growing number of platforms implement IPv6, and APR supports
81 IPv6 on most of these platforms, allowing Apache to allocate IPv6
82 sockets and handle requests which were sent over IPv6.</p>
84 <p>One complicating factor for Apache administrators is whether or
85 not an IPv6 socket can handle both IPv4 connections and IPv6
86 connections. Handling IPv4 connections with an IPv6 socket uses
87 IPv4-mapped IPv6 addresses, which are allowed by default on most
88 platforms but are disallowed by default on FreeBSD, NetBSD, and
89 OpenBSD in order to match the system-wide policy on those
90 platforms. But even on systems where it is disallowed by default, a
91 special configure parameter can change this behavior for Apache.</p>
93 <p>If you want Apache to handle IPv4 and IPv6 connections with a
94 minimum of sockets, which requires using IPv4-mapped IPv6 addresses,
95 specify the <code>--enable-v4-mapped</code> configure option and use
96 generic Listen directives like the following:</p>
102 <p>With <code>--enable-v4-mapped</code>, the Listen directives in the
103 default configuration file created by Apache will use this form.
104 <code>--enable-v4-mapped</code> is the default on all platforms but
105 FreeBSD, NetBSD, and OpenBSD, so this is probably how your Apache was
108 <p>If you want Apache to handle IPv4 connections only, regardless of
109 what your platform and APR will support, specify an IPv4 address on all
110 Listen directives, as in the following examples:</p>
113 Listen 0.0.0.0:80<br />
114 Listen 192.170.2.1:80
117 <p>If you want Apache to handle IPv4 and IPv6 connections on separate
118 sockets (i.e., to disable IPv4-mapped addresses), specify the
119 <code>--disable-v4-mapped</code> configure option and use specific Listen
120 directives like the following:</p>
127 <p>With <code>--disable-v4-mapped</code>, the Listen directives in the
128 default configuration file created by Apache will use this form.
129 <code>--disable-v4-mapped</code> is the default on FreeBSD, NetBSD, and
134 <section id="virtualhost">
135 <title>How This Works With Virtual Hosts</title>
137 <p>Listen does not implement Virtual Hosts. It only tells the
138 main server what addresses and ports to listen to. If no
139 <directive module="core" type="section">VirtualHost</directive>
140 directives are used, the server will behave
141 the same for all accepted requests. However,
142 <directive module="core" type="section">VirtualHost</directive>
143 can be used to specify a different behavior
144 for one or more of the addresses and ports. To implement a
145 VirtualHost, the server must first be told to listen to the
146 address and port to be used. Then a
147 <directive module="core" type="section">VirtualHost</directive> section
148 should be created for a specified address and port to set the
149 behavior of this virtual host. Note that if the
150 <directive module="core" type="section">VirtualHost</directive>
151 is set for an address and port that the
152 server is not listening to, it cannot be accessed.</p>