]> granicus.if.org Git - apache/blob - docs/manual/bind.html.en
Help doc writer to spot places where:
[apache] / docs / manual / bind.html.en
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
4 <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
5 <!--
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7               This file is generated from xml source: DO NOT EDIT
8         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9       -->
10 <title>Binding to Addresses and Ports - Apache HTTP Server Version 2.5</title>
11 <link href="./style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
12 <link href="./style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
13 <link href="./style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="./style/css/prettify.css" />
14 <script src="./style/scripts/prettify.min.js" type="text/javascript">
15 </script>
16
17 <link href="./images/favicon.ico" rel="shortcut icon" /></head>
18 <body id="manual-page"><div id="page-header">
19 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p>
20 <p class="apache">Apache HTTP Server Version 2.5</p>
21 <img alt="" src="./images/feather.png" /></div>
22 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="./images/left.gif" /></a></div>
23 <div id="path">
24 <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="./">Version 2.5</a></div><div id="page-content"><div id="preamble"><h1>Binding to Addresses and Ports</h1>
25 <div class="toplang">
26 <p><span>Available Languages: </span><a href="./de/bind.html" hreflang="de" rel="alternate" title="Deutsch">&nbsp;de&nbsp;</a> |
27 <a href="./en/bind.html" title="English">&nbsp;en&nbsp;</a> |
28 <a href="./es/bind.html" hreflang="es" rel="alternate" title="Español">&nbsp;es&nbsp;</a> |
29 <a href="./fr/bind.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
30 <a href="./ja/bind.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
31 <a href="./ko/bind.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
32 <a href="./tr/bind.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
33 </div>
34
35     <p>Configuring Apache HTTP Server to listen on specific addresses and ports.</p>
36   </div>
37 <div id="quickview"><ul id="toc"><li><img alt="" src="./images/down.gif" /> <a href="#overview">Overview</a></li>
38 <li><img alt="" src="./images/down.gif" /> <a href="#reload">Changing Listen configuration on restart</a></li>
39 <li><img alt="" src="./images/down.gif" /> <a href="#ipv6">Special IPv6 Considerations</a></li>
40 <li><img alt="" src="./images/down.gif" /> <a href="#protocol">Specifying the protocol with Listen</a></li>
41 <li><img alt="" src="./images/down.gif" /> <a href="#virtualhost">How This Works With Virtual Hosts</a></li>
42 </ul><h3>See also</h3><ul class="seealso"><li><a href="vhosts/">Virtual Hosts</a></li><li><a href="dns-caveats.html">DNS Issues</a></li><li><a href="#comments_section">Comments</a></li></ul></div>
43 <div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
44 <div class="section">
45 <h2><a name="overview" id="overview">Overview</a> <a title="Permanent link" href="#overview" class="permalink">&para;</a></h2>
46     
47
48     <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="./mod/core.html">core</a></code></li><li><code class="module"><a href="./mod/mpm_common.html">mpm_common</a></code></li></ul></td><td><ul><li><code class="directive"><a href="./mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code></li><li><code class="directive"><a href="./mod/mpm_common.html#listen">Listen</a></code></li></ul></td></tr></table>
49
50
51     <p>When httpd starts, it binds to some port and address on
52     the local machine and waits for incoming requests. By default,
53     it listens to all addresses on the machine. However, it may need to
54     be told to listen on specific ports, or only on selected
55     addresses, or a combination of both. This is often combined with the
56     <a href="vhosts/">Virtual Host</a> feature, which determines how
57     <code>httpd</code> responds to different IP addresses, hostnames and
58     ports.</p>
59
60     <p>The <code class="directive"><a href="./mod/mpm_common.html#listen">Listen</a></code>
61     directive tells the server to accept
62     incoming requests only on the specified port(s) or
63     address-and-port combinations. If only a port number is
64     specified in the <code class="directive"><a href="./mod/mpm_common.html#listen">Listen</a></code>
65     directive, the server listens to the given port on all interfaces.
66     If an IP address is given as well as a port, the server will listen
67     on the given port and interface. Multiple <code class="directive"><a href="./mod/mpm_common.html#listen">Listen</a></code> directives may be used to
68     specify a number of addresses and ports to listen on. The
69     server will respond to requests from any of the listed
70     addresses and ports.</p>
71
72     <p>For example, to make the server accept connections on both
73     port 80 and port 8000, on all interfaces, use:</p>
74
75     <div class="example"><pre class="prettyprint lang-config">Listen 80
76 Listen 8000</pre>
77 </div>
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     <div class="example"><pre class="prettyprint lang-config">Listen 192.0.2.1:80
83 Listen 192.0.2.5:8000</pre>
84 </div>
85
86     <p>IPv6 addresses must be enclosed in square brackets, as in the
87     following example:</p>
88
89     <div class="example"><pre class="prettyprint lang-config">Listen [2001:db8::a00:20ff:fea7:ccea]:80</pre>
90 </div>
91
92     <div class="warning"><p>Overlapping <code class="directive"><a href="./mod/mpm_common.html#listen">Listen</a></code> directives will result in a
93     fatal error which will prevent the server from starting up.</p>
94
95     <div class="example"><p><code>
96       (48)Address already in use: make_sock: could not bind to address [::]:80
97     </code></p></div>
98
99     <p>See <a href="http://wiki.apache.org/httpd/CouldNotBindToAddress">the
100     discussion in the wiki</a> for further troubleshooting tips.</p>
101
102 </div>
103
104   </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
105 <div class="section">
106 <h2><a name="reload" id="reload">Changing Listen configuration on restart</a> <a title="Permanent link" href="#reload" class="permalink">&para;</a></h2>
107     
108
109     <p>When httpd is restarted, special consideration must be made for
110     changes to <code class="directive"><a href="./mod/mpm_common.html#listen">Listen</a></code> directives.  During a restart, httpd keeps ports
111     bound (as in the original configuration) to avoid generating
112     "Connection refused" errors for any new attempts to connect to the
113     server. If changes are made to the set of <code class="directive"><a href="./mod/mpm_common.html#listen">Listen</a></code> directives used
114     which conflict with the old configuration, configuration will fail
115     and the server will terminate.</p>
116
117     <p>For example, changing from configuration:</p>
118     
119     <div class="example"><pre class="prettyprint lang-config">Listen 127.0.0.1:80</pre>
120 </div>
121
122     <p>to the following may fail, because binding to port 80 across
123     all addresses conflicts with binding to port 80 on just
124     127.0.0.1.</p>
125     
126     <div class="example"><pre class="prettyprint lang-config">Listen 80</pre>
127 </div>
128
129     <p>To have such configuration changes take effect, it is necessary
130     to stop and then start the server.</p>
131     
132   </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
133 <div class="section">
134 <h2><a name="ipv6" id="ipv6">Special IPv6 Considerations</a> <a title="Permanent link" href="#ipv6" class="permalink">&para;</a></h2>
135     
136
137     <p>A growing number of platforms implement IPv6, and
138     <a class="glossarylink" href="./glossary.html#apr" title="see glossary">APR</a> supports IPv6 on most of these platforms,
139     allowing httpd to allocate IPv6 sockets, and to handle requests sent
140     over IPv6.</p>
141
142     <p>One complicating factor for httpd administrators is whether or
143     not an IPv6 socket can handle both IPv4 connections and IPv6
144     connections. Handling IPv4 connections with an IPv6 socket uses
145     IPv4-mapped IPv6 addresses, which are allowed by default on most
146     platforms, but are disallowed by default on FreeBSD, NetBSD, and
147     OpenBSD, in order to match the system-wide policy on those
148     platforms. On systems where it is disallowed by default, a
149     special <code class="program"><a href="./programs/configure.html">configure</a></code> parameter can change this behavior
150     for httpd.</p>
151
152     <p>On the other hand, on some platforms, such as Linux and Tru64, the
153     <strong>only</strong> way to handle both IPv6 and IPv4 is to use
154     mapped addresses. If you want <code>httpd</code> to handle IPv4 and IPv6 connections
155     with a minimum of sockets, which requires using IPv4-mapped IPv6
156     addresses, specify the <code>--enable-v4-mapped</code> <code class="program"><a href="./programs/configure.html">configure</a></code> option.</p>
157
158     <p><code>--enable-v4-mapped</code> is the default on all platforms except
159     FreeBSD, NetBSD, and OpenBSD, so this is probably how your httpd was
160     built.</p>
161
162     <p>If you want httpd to handle IPv4 connections only, regardless of
163     what your platform and APR will support, specify an IPv4 address on all
164     <code class="directive"><a href="./mod/mpm_common.html#listen">Listen</a></code> directives, as in the
165     following examples:</p>
166
167     <div class="example"><pre class="prettyprint lang-config">Listen 0.0.0.0:80
168 Listen 192.0.2.1:80</pre>
169 </div>
170
171     <p>If your platform supports it and you want httpd to handle IPv4 and
172     IPv6 connections on separate sockets (i.e., to disable IPv4-mapped
173     addresses), specify the <code>--disable-v4-mapped</code> <code class="program"><a href="./programs/configure.html">configure</a></code> option. <code>--disable-v4-mapped</code> is the
174     default on FreeBSD, NetBSD, and OpenBSD.</p>
175   </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
176 <div class="section">
177 <h2><a name="protocol" id="protocol">Specifying the protocol with Listen</a> <a title="Permanent link" href="#protocol" class="permalink">&para;</a></h2>
178     
179     <p>The optional second <var>protocol</var> argument of
180        <code class="directive"><a href="./mod/mpm_common.html#listen">Listen</a></code>
181        is not required for most
182        configurations. If not specified, <code>https</code> is the default for
183        port 443 and <code>http</code> the default for all other ports.  The
184        protocol is used to determine which module should handle a request, and
185        to apply protocol specific optimizations with the
186        <code class="directive"><a href="./mod/core.html#acceptfilter">AcceptFilter</a></code> directive.</p>
187
188     <p>You only need to set the protocol if you are running on non-standard
189        ports.  For example, running an <code>https</code> site on port 8443:</p>
190
191     <div class="example"><pre class="prettyprint lang-config">Listen 192.170.2.1:8443 https</pre>
192 </div>
193   </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
194 <div class="section">
195 <h2><a name="virtualhost" id="virtualhost">How This Works With Virtual Hosts</a> <a title="Permanent link" href="#virtualhost" class="permalink">&para;</a></h2>
196     
197
198     <p> The <code class="directive"><a href="./mod/mpm_common.html#listen">Listen</a></code> directive does not implement
199     Virtual Hosts - it only tells the
200     main server what addresses and ports to listen on. If no
201     <code class="directive"><a href="./mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
202     directives are used, the server will behave
203     in the same way for all accepted requests. However,
204     <code class="directive"><a href="./mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
205     can be used to specify a different behavior
206     for one or more of the addresses or ports. To implement a
207     VirtualHost, the server must first be told to listen to the
208     address and port to be used. Then a
209     <code class="directive"><a href="./mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code> section
210     should be created for the specified address and port to set the
211     behavior of this virtual host. Note that if the
212     <code class="directive"><a href="./mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
213     is set for an address and port that the
214     server is not listening to, it cannot be accessed.</p>
215   </div></div>
216 <div class="bottomlang">
217 <p><span>Available Languages: </span><a href="./de/bind.html" hreflang="de" rel="alternate" title="Deutsch">&nbsp;de&nbsp;</a> |
218 <a href="./en/bind.html" title="English">&nbsp;en&nbsp;</a> |
219 <a href="./es/bind.html" hreflang="es" rel="alternate" title="Español">&nbsp;es&nbsp;</a> |
220 <a href="./fr/bind.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
221 <a href="./ja/bind.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
222 <a href="./ko/bind.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
223 <a href="./tr/bind.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
224 </div><div class="top"><a href="#page-header"><img src="./images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
225 <script type="text/javascript"><!--//--><![CDATA[//><!--
226 var comments_shortname = 'httpd';
227 var comments_identifier = 'http://httpd.apache.org/docs/trunk/bind.html';
228 (function(w, d) {
229     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
230         d.write('<div id="comments_thread"><\/div>');
231         var s = d.createElement('script');
232         s.type = 'text/javascript';
233         s.async = true;
234         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
235         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
236     }
237     else {
238         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
239     }
240 })(window, document);
241 //--><!]]></script></div><div id="footer">
242 <p class="apache">Copyright 2019 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
243 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
244 if (typeof(prettyPrint) !== 'undefined') {
245     prettyPrint();
246 }
247 //--><!]]></script>
248 </body></html>