]> granicus.if.org Git - apache/blob - docs/manual/bind.xml
- remove link to a different doc version (not suitable for any other viewing than
[apache] / docs / manual / bind.xml
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"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <manualpage metafile="bind.xml.meta">
24
25   <title>Binding to Addresses and Ports</title>
26
27   <summary>
28     <p>Configuring Apache HTTP Server to listen on specific addresses and ports.</p>
29   </summary>
30
31   <seealso><a href="vhosts/">Virtual Hosts</a></seealso>
32   <seealso><a href="dns-caveats.html">DNS Issues</a></seealso>
33
34   <section id="overview">
35     <title>Overview</title>
36
37     <related>
38       <modulelist>
39         <module>core</module>
40         <module>mpm_common</module>
41       </modulelist>
42       <directivelist>
43         <directive module="core" type="section">VirtualHost</directive>
44         <directive module="mpm_common">Listen</directive>
45       </directivelist>
46     </related>
47
48
49     <p>When httpd starts, it binds to some port and address on
50     the local machine and waits for incoming requests. By default,
51     it listens to all addresses on the machine. However, it may need to
52     be told to listen on specific ports, or only on selected
53     addresses, or a combination of both. This is often combined with the
54     <a href="vhosts/">Virtual Host</a> feature, which determines how
55     <code>httpd</code> responds to different IP addresses, hostnames and
56     ports.</p>
57
58     <p>The <directive module="mpm_common">Listen</directive>
59     directive tells the server to accept
60     incoming requests only on the specified port(s) or
61     address-and-port combinations. If only a port number is
62     specified in the <directive module="mpm_common">Listen</directive>
63     directive, the server listens to the given port on all interfaces.
64     If an IP address is given as well as a port, the server will listen
65     on the given port and interface. Multiple <directive
66     module="mpm_common">Listen</directive> directives may be used to
67     specify a number of addresses and ports to listen on. The
68     server will respond to requests from any of the listed
69     addresses and ports.</p>
70
71     <p>For example, to make the server accept connections on both
72     port 80 and port 8000, on all interfaces, use:</p>
73
74     <highlight language="config">
75 Listen 80
76 Listen 8000
77     </highlight>
78
79     <p>To make the server accept connections on port 80 for one interface,
80        and port 8000 on another, use</p>
81
82     <highlight language="config">
83 Listen 192.0.2.1:80
84 Listen 192.0.2.5:8000
85     </highlight>
86
87     <p>IPv6 addresses must be enclosed in square brackets, as in the
88     following example:</p>
89
90     <highlight language="config">
91       Listen [2001:db8::a00:20ff:fea7:ccea]:80
92     </highlight>
93
94     <note type="warning"><p>Overlapping <directive
95     module="mpm_common">Listen</directive> directives will result in a
96     fatal error which will prevent the server from starting up.</p>
97
98     <example>
99     (48)Address already in use: make_sock: could not bind to address [::]:80
100     </example>
101
102     <p>See <a 
103     href="http://wiki.apache.org/httpd/CouldNotBindToAddress">the
104     discussion in the wiki</a> for further troubleshooting tips.</p>
105
106 </note>
107
108   </section>
109
110   <section id="ipv6">
111     <title>Special IPv6 Considerations</title>
112
113     <p>A growing number of platforms implement IPv6, and
114     <glossary>APR</glossary> supports IPv6 on most of these platforms,
115     allowing httpd to allocate IPv6 sockets, and to handle requests sent
116     over IPv6.</p>
117
118     <p>One complicating factor for httpd administrators is whether or
119     not an IPv6 socket can handle both IPv4 connections and IPv6
120     connections. Handling IPv4 connections with an IPv6 socket uses
121     IPv4-mapped IPv6 addresses, which are allowed by default on most
122     platforms, but are disallowed by default on FreeBSD, NetBSD, and
123     OpenBSD, in order to match the system-wide policy on those
124     platforms. On systems where it is disallowed by default, a
125     special <program>configure</program> parameter can change this behavior
126     for httpd.</p>
127
128     <p>On the other hand, on some platforms, such as Linux and Tru64, the
129     <strong>only</strong> way to handle both IPv6 and IPv4 is to use
130     mapped addresses. If you want <code>httpd</code> to handle IPv4 and IPv6 connections
131     with a minimum of sockets, which requires using IPv4-mapped IPv6
132     addresses, specify the <code>--enable-v4-mapped</code> <program>
133     configure</program> option.</p>
134
135     <p><code>--enable-v4-mapped</code> is the default on all platforms except
136     FreeBSD, NetBSD, and OpenBSD, so this is probably how your httpd was
137     built.</p>
138
139     <p>If you want httpd to handle IPv4 connections only, regardless of
140     what your platform and APR will support, specify an IPv4 address on all
141     <directive module="mpm_common">Listen</directive> directives, as in the
142     following examples:</p>
143
144     <highlight language="config">
145 Listen 0.0.0.0:80
146 Listen 192.0.2.1:80
147     </highlight>
148
149     <p>If your platform supports it and you want httpd to handle IPv4 and
150     IPv6 connections on separate sockets (i.e., to disable IPv4-mapped
151     addresses), specify the <code>--disable-v4-mapped</code> <program>
152     configure</program> option. <code>--disable-v4-mapped</code> is the
153     default on FreeBSD, NetBSD, and OpenBSD.</p>
154   </section>
155
156   <section id="protocol">
157     <title>Specifying the protocol with Listen</title>
158     <p>The optional second <var>protocol</var> argument of
159        <directive module="mpm_common">Listen</directive>
160        is not required for most
161        configurations. If not specified, <code>https</code> is the default for
162        port 443 and <code>http</code> the default for all other ports.  The
163        protocol is used to determine which module should handle a request, and
164        to apply protocol specific optimizations with the
165        <directive module="core">AcceptFilter</directive> directive.</p>
166
167     <p>You only need to set the protocol if you are running on non-standard
168        ports.  For example, running an <code>https</code> site on port 8443:</p>
169
170     <highlight language="config">
171       Listen 192.170.2.1:8443 https
172     </highlight>
173   </section>
174
175   <section id="virtualhost">
176     <title>How This Works With Virtual Hosts</title>
177
178     <p> The <directive
179     module="mpm_common">Listen</directive> directive does not implement
180     Virtual Hosts - it only tells the
181     main server what addresses and ports to listen on. If no
182     <directive module="core" type="section">VirtualHost</directive>
183     directives are used, the server will behave
184     in the same way for all accepted requests. However,
185     <directive module="core" type="section">VirtualHost</directive>
186     can be used to specify a different behavior
187     for one or more of the addresses or ports. To implement a
188     VirtualHost, the server must first be told to listen to the
189     address and port to be used. Then a
190     <directive module="core" type="section">VirtualHost</directive> section
191     should be created for the specified address and port to set the
192     behavior of this virtual host. Note that if the
193     <directive module="core" type="section">VirtualHost</directive>
194     is set for an address and port that the
195     server is not listening to, it cannot be accessed.</p>
196   </section>
197 </manualpage>
198