bind.xml revision f50095bc3874806a9cc5e7d283dd9051ef8a0df8
b442af56a5e2104663b84fb345c070ce185d4ab3slive<?xml version="1.0" encoding="UTF-8" ?>
b442af56a5e2104663b84fb345c070ce185d4ab3slive<!DOCTYPE manualpage SYSTEM "/style/manualpage.dtd">
b442af56a5e2104663b84fb345c070ce185d4ab3slive<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
5f5d1b4cc970b7f06ff8ef6526128e9a27303d88nd<!-- $LastChangedRevision$ -->
b442af56a5e2104663b84fb345c070ce185d4ab3slive
acc36ab93565d2880447d535da6ca6e5feac7a70nd<!--
6fbd2e53c97ea6976d93e0ac521adabc55e0fb73nd Licensed to the Apache Software Foundation (ASF) under one or more
acc36ab93565d2880447d535da6ca6e5feac7a70nd contributor license agreements. See the NOTICE file distributed with
acc36ab93565d2880447d535da6ca6e5feac7a70nd this work for additional information regarding copyright ownership.
acc36ab93565d2880447d535da6ca6e5feac7a70nd The ASF licenses this file to You under the Apache License, Version 2.0
acc36ab93565d2880447d535da6ca6e5feac7a70nd (the "License"); you may not use this file except in compliance with
acc36ab93565d2880447d535da6ca6e5feac7a70nd the License. You may obtain a copy of the License at
acc36ab93565d2880447d535da6ca6e5feac7a70nd
acc36ab93565d2880447d535da6ca6e5feac7a70nd http://www.apache.org/licenses/LICENSE-2.0
acc36ab93565d2880447d535da6ca6e5feac7a70nd
acc36ab93565d2880447d535da6ca6e5feac7a70nd Unless required by applicable law or agreed to in writing, software
acc36ab93565d2880447d535da6ca6e5feac7a70nd distributed under the License is distributed on an "AS IS" BASIS,
acc36ab93565d2880447d535da6ca6e5feac7a70nd WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
acc36ab93565d2880447d535da6ca6e5feac7a70nd See the License for the specific language governing permissions and
acc36ab93565d2880447d535da6ca6e5feac7a70nd limitations under the License.
acc36ab93565d2880447d535da6ca6e5feac7a70nd-->
7db9f691a00ead175b03335457ca296a33ddf31bnd
b442af56a5e2104663b84fb345c070ce185d4ab3slive<manualpage metafile="bind.xml.meta">
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <title>Binding to Addresses and Ports</title>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <summary>
b442af56a5e2104663b84fb345c070ce185d4ab3slive <p>Configuring Apache HTTP Server to listen on specific addresses and ports.</p>
38a01d3776f9a98839742b8f024ecb4d0d2ea613jsl </summary>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <seealso><a href="vhosts/">Virtual Hosts</a></seealso>
b442af56a5e2104663b84fb345c070ce185d4ab3slive <seealso><a href="dns-caveats.html">DNS Issues</a></seealso>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <section id="overview">
38a01d3776f9a98839742b8f024ecb4d0d2ea613jsl <title>Overview</title>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <related>
b442af56a5e2104663b84fb345c070ce185d4ab3slive <modulelist>
b442af56a5e2104663b84fb345c070ce185d4ab3slive <module>core</module>
b442af56a5e2104663b84fb345c070ce185d4ab3slive <module>mpm_common</module>
b442af56a5e2104663b84fb345c070ce185d4ab3slive </modulelist>
09ad82b467d18345648fe3fa155a5914984980dfnd <directivelist>
b442af56a5e2104663b84fb345c070ce185d4ab3slive <directive module="core" type="section">VirtualHost</directive>
b442af56a5e2104663b84fb345c070ce185d4ab3slive <directive module="mpm_common">Listen</directive>
b442af56a5e2104663b84fb345c070ce185d4ab3slive </directivelist>
38a01d3776f9a98839742b8f024ecb4d0d2ea613jsl </related>
38a01d3776f9a98839742b8f024ecb4d0d2ea613jsl
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <p>When httpd starts, it binds to some port and address on
b442af56a5e2104663b84fb345c070ce185d4ab3slive the local machine and waits for incoming requests. By default,
b442af56a5e2104663b84fb345c070ce185d4ab3slive it listens to all addresses on the machine. However, it may need to
b442af56a5e2104663b84fb345c070ce185d4ab3slive be told to listen on specific ports, or only on selected
b442af56a5e2104663b84fb345c070ce185d4ab3slive addresses, or a combination of both. This is often combined with the
b442af56a5e2104663b84fb345c070ce185d4ab3slive <a href="vhosts/">Virtual Host</a> feature, which determines how
b442af56a5e2104663b84fb345c070ce185d4ab3slive <code>httpd</code> responds to different IP addresses, hostnames and
9530629c5ba74f47ba0bad2cd4f432c9c5cd4ff4slive ports.</p>
9530629c5ba74f47ba0bad2cd4f432c9c5cd4ff4slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <p>The <directive module="mpm_common">Listen</directive>
b442af56a5e2104663b84fb345c070ce185d4ab3slive directive tells the server to accept
9530629c5ba74f47ba0bad2cd4f432c9c5cd4ff4slive incoming requests only on the specified port(s) or
9530629c5ba74f47ba0bad2cd4f432c9c5cd4ff4slive address-and-port combinations. If only a port number is
b442af56a5e2104663b84fb345c070ce185d4ab3slive specified in the <directive module="mpm_common">Listen</directive>
b442af56a5e2104663b84fb345c070ce185d4ab3slive directive, the server listens to the given port on all interfaces.
efcdf6bd09d3edaacd4db8e3b6af0678a1201d52kess If an IP address is given as well as a port, the server will listen
efcdf6bd09d3edaacd4db8e3b6af0678a1201d52kess on the given port and interface. Multiple <directive
b442af56a5e2104663b84fb345c070ce185d4ab3slive module="mpm_common">Listen</directive> directives may be used to
b442af56a5e2104663b84fb345c070ce185d4ab3slive specify a number of addresses and ports to listen on. The
b442af56a5e2104663b84fb345c070ce185d4ab3slive server will respond to requests from any of the listed
b442af56a5e2104663b84fb345c070ce185d4ab3slive addresses and ports.</p>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <p>For example, to make the server accept connections on both
b442af56a5e2104663b84fb345c070ce185d4ab3slive port 80 and port 8000, on all interfaces, use:</p>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <highlight language="config">
b442af56a5e2104663b84fb345c070ce185d4ab3sliveListen 80
b442af56a5e2104663b84fb345c070ce185d4ab3sliveListen 8000
b442af56a5e2104663b84fb345c070ce185d4ab3slive </highlight>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <p>To make the server accept connections on port 80 for one interface,
b442af56a5e2104663b84fb345c070ce185d4ab3slive and port 8000 on another, use</p>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <highlight language="config">
b442af56a5e2104663b84fb345c070ce185d4ab3sliveListen 192.0.2.1:80
b442af56a5e2104663b84fb345c070ce185d4ab3sliveListen 192.0.2.5:8000
b442af56a5e2104663b84fb345c070ce185d4ab3slive </highlight>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <p>IPv6 addresses must be enclosed in square brackets, as in the
b442af56a5e2104663b84fb345c070ce185d4ab3slive following example:</p>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <highlight language="config">
b442af56a5e2104663b84fb345c070ce185d4ab3slive Listen [2001:db8::a00:20ff:fea7:ccea]:80
b442af56a5e2104663b84fb345c070ce185d4ab3slive </highlight>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <note type="warning"><p>Overlapping <directive
b442af56a5e2104663b84fb345c070ce185d4ab3slive module="mpm_common">Listen</directive> directives will result in a
b442af56a5e2104663b84fb345c070ce185d4ab3slive fatal error which will prevent the server from starting up.</p>
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick <example>
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick (48)Address already in use: make_sock: could not bind to address [::]:80
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick </example>
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick <p>See <a
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick href="http://wiki.apache.org/httpd/CouldNotBindToAddress">the
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick discussion in the wiki</a> for further troubleshooting tips.</p>
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick</note>
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick </section>
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick
ef26e16090b1b00e96bb5eb1bee6f9cee4651466jwoolley <section id="ipv6">
ef26e16090b1b00e96bb5eb1bee6f9cee4651466jwoolley <title>Special IPv6 Considerations</title>
ef26e16090b1b00e96bb5eb1bee6f9cee4651466jwoolley
ef26e16090b1b00e96bb5eb1bee6f9cee4651466jwoolley <p>A growing number of platforms implement IPv6, and
efcdf6bd09d3edaacd4db8e3b6af0678a1201d52kess <glossary>APR</glossary> supports IPv6 on most of these platforms,
efcdf6bd09d3edaacd4db8e3b6af0678a1201d52kess allowing httpd to allocate IPv6 sockets, and to handle requests sent
ef26e16090b1b00e96bb5eb1bee6f9cee4651466jwoolley over IPv6.</p>
ef26e16090b1b00e96bb5eb1bee6f9cee4651466jwoolley
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick <p>One complicating factor for httpd administrators is whether or
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick not an IPv6 socket can handle both IPv4 connections and IPv6
b442af56a5e2104663b84fb345c070ce185d4ab3slive connections. Handling IPv4 connections with an IPv6 socket uses
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick IPv4-mapped IPv6 addresses, which are allowed by default on most
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick platforms, but are disallowed by default on FreeBSD, NetBSD, and
efcdf6bd09d3edaacd4db8e3b6af0678a1201d52kess OpenBSD, in order to match the system-wide policy on those
efcdf6bd09d3edaacd4db8e3b6af0678a1201d52kess platforms. On systems where it is disallowed by default, a
b442af56a5e2104663b84fb345c070ce185d4ab3slive special <program>configure</program> parameter can change this behavior
b442af56a5e2104663b84fb345c070ce185d4ab3slive for httpd.</p>
b4600e71d7e8201b3c14c67f4ef873cadd4c1d17trawick
4566c682d671cfda9cfcb77ea3f8e3fb8a265010trawick <p>On the other hand, on some platforms, such as Linux and Tru64, the
b442af56a5e2104663b84fb345c070ce185d4ab3slive <strong>only</strong> way to handle both IPv6 and IPv4 is to use
b442af56a5e2104663b84fb345c070ce185d4ab3slive mapped addresses. If you want <code>httpd</code> to handle IPv4 and IPv6 connections
ef26e16090b1b00e96bb5eb1bee6f9cee4651466jwoolley with a minimum of sockets, which requires using IPv4-mapped IPv6
ef26e16090b1b00e96bb5eb1bee6f9cee4651466jwoolley addresses, specify the <code>--enable-v4-mapped</code> <program>
efcdf6bd09d3edaacd4db8e3b6af0678a1201d52kess configure</program> option.</p>
efcdf6bd09d3edaacd4db8e3b6af0678a1201d52kess
efcdf6bd09d3edaacd4db8e3b6af0678a1201d52kess <p><code>--enable-v4-mapped</code> is the default on all platforms except
ef26e16090b1b00e96bb5eb1bee6f9cee4651466jwoolley FreeBSD, NetBSD, and OpenBSD, so this is probably how your httpd was
b442af56a5e2104663b84fb345c070ce185d4ab3slive built.</p>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <p>If you want httpd to handle IPv4 connections only, regardless of
b442af56a5e2104663b84fb345c070ce185d4ab3slive what your platform and APR will support, specify an IPv4 address on all
b442af56a5e2104663b84fb345c070ce185d4ab3slive <directive module="mpm_common">Listen</directive> directives, as in the
efcdf6bd09d3edaacd4db8e3b6af0678a1201d52kess following examples:</p>
efcdf6bd09d3edaacd4db8e3b6af0678a1201d52kess
efcdf6bd09d3edaacd4db8e3b6af0678a1201d52kess <highlight language="config">
b442af56a5e2104663b84fb345c070ce185d4ab3sliveListen 0.0.0.0:80
9530629c5ba74f47ba0bad2cd4f432c9c5cd4ff4sliveListen 192.0.2.1:80
9530629c5ba74f47ba0bad2cd4f432c9c5cd4ff4slive </highlight>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
9530629c5ba74f47ba0bad2cd4f432c9c5cd4ff4slive <p>If your platform supports it and you want httpd to handle IPv4 and
9530629c5ba74f47ba0bad2cd4f432c9c5cd4ff4slive IPv6 connections on separate sockets (i.e., to disable IPv4-mapped
b442af56a5e2104663b84fb345c070ce185d4ab3slive addresses), specify the <code>--disable-v4-mapped</code> <program>
b442af56a5e2104663b84fb345c070ce185d4ab3slive configure</program> option. <code>--disable-v4-mapped</code> is the
9530629c5ba74f47ba0bad2cd4f432c9c5cd4ff4slive default on FreeBSD, NetBSD, and OpenBSD.</p>
9530629c5ba74f47ba0bad2cd4f432c9c5cd4ff4slive </section>
b442af56a5e2104663b84fb345c070ce185d4ab3slive
b442af56a5e2104663b84fb345c070ce185d4ab3slive <section id="protocol">
9530629c5ba74f47ba0bad2cd4f432c9c5cd4ff4slive <title>Specifying the protocol with Listen</title>
9530629c5ba74f47ba0bad2cd4f432c9c5cd4ff4slive <p>The optional second <var>protocol</var> argument of
b442af56a5e2104663b84fb345c070ce185d4ab3slive <directive module="mpm_common">Listen</directive>
b442af56a5e2104663b84fb345c070ce185d4ab3slive is not required for most
b442af56a5e2104663b84fb345c070ce185d4ab3slive configurations. If not specified, <code>https</code> is the default for
b442af56a5e2104663b84fb345c070ce185d4ab3slive port 443 and <code>http</code> the default for all other ports. The
protocol is used to determine which module should handle a request, and
to apply protocol specific optimizations with the
<directive module="core">AcceptFilter</directive> directive.</p>
<p>You only need to set the protocol if you are running on non-standard
ports. For example, running an <code>https</code> site on port 8443:</p>
<highlight language="config">
Listen 192.170.2.1:8443 https
</highlight>
</section>
<section id="virtualhost">
<title>How This Works With Virtual Hosts</title>
<p> The <directive
module="mpm_common">Listen</directive> directive does not implement
Virtual Hosts - it only tells the
main server what addresses and ports to listen on. If no
<directive module="core" type="section">VirtualHost</directive>
directives are used, the server will behave
in the same way for all accepted requests. However,
<directive module="core" type="section">VirtualHost</directive>
can be used to specify a different behavior
for one or more of the addresses or ports. To implement a
VirtualHost, the server must first be told to listen to the
address and port to be used. Then a
<directive module="core" type="section">VirtualHost</directive> section
should be created for the specified address and port to set the
behavior of this virtual host. Note that if the
<directive module="core" type="section">VirtualHost</directive>
is set for an address and port that the
server is not listening to, it cannot be accessed.</p>
</section>
</manualpage>