]> granicus.if.org Git - apache/blob - docs/manual/bind.xml
Replace some <code> with <directive>
[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
5 <manualpage>
6   <relativepath href="."/>
7
8   <title>Binding</title>
9
10   <summary>
11     <p>Configuring Apache to listen on specific addresses and ports.</p>
12   </summary>
13   
14   <seealso><a href="vhosts/">Virtual Hosts</a></seealso>
15   <seealso><a href="dns-caveats.html">DNS Issues</a></seealso>
16
17   <section id="overview">
18     <title>Overview</title>
19     
20     <related>
21       <modulelist>
22         <module>core</module>
23         <module>mpm_common</module>
24       </modulelist>
25       <directivelist>
26         <directive module="core">VirtualHost</directive>
27         <directive module="mpm_common">Listen</directive>
28       </directivelist>
29     </related>
30     
31     
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>
39
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>
45     directive, the server
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>
52
53     <p>For example, to make the server accept connections on both
54     port 80 and port 8000, use:</p>
55
56     <example>
57       Listen 80<br />
58       Listen 8000
59     </example>
60
61     <p>To make the server accept connections on two specified
62     interfaces and port numbers, use</p>
63
64     <example>
65       Listen 192.170.2.1:80<br />
66       Listen 192.170.2.5:8000
67     </example>
68
69     <p>IPv6 addresses must be surrounded in square brackets, as in the
70     following example:</p>
71
72     <example>
73       Listen [fe80::a00:20ff:fea7:ccea]:80
74     </example>
75   </section>
76
77   <section id="ipv6">
78     <title>Special IPv6 Considerations</title>
79
80     <p>When APR supports IPv6, Apache will create IPv6-capable listening
81     sockets by default (i.e., when no IP address is specified on the
82     Listen directive).  In other words, when APR supports IPv6,</p>
83
84     <example>
85       Listen 80
86     </example>
87
88     <p>is equivalent to</p>
89
90     <example>
91       Listen [::]:80
92     </example>
93
94     <p>When APR does not support IPv6,</p>
95
96     <example>
97       Listen 80
98     </example>
99
100     <p>is equivalent to</p>
101
102     <example>
103       Listen 0.0.0.0:80
104     </example>
105
106     <p>On some platforms, such as NetBSD, binding to the IPv6 wildcard address 
107     ("::") does not allow Apache to accept connections on IPv4 interfaces.
108     In this situation, multiple Listen directives are required, as shown
109     below:</p>
110
111     <example>
112       Listen 0.0.0.0:80<br />
113       Listen [::]:0
114     </example>
115
116     <p>Apache does not currently detect this, so the Listen statements must
117     be edited manually by the administrator.</p>
118   </section>
119
120   <section id="virtualhost">
121     <title>How This Works With Virtual Hosts</title>
122
123     <p>Listen does not implement Virtual Hosts. It only tells the
124     main server what addresses and ports to listen to. If no
125     <directive module="core" type="section">VirtualHost</directive>
126     directives are used, the server will behave
127     the same for all accepted requests. However,
128     <directive module="core" type="section">VirtualHost</directive>
129     can be used to specify a different behavior
130     for one or more of the addresses and ports. To implement a
131     VirtualHost, the server must first be told to listen to the
132     address and port to be used. Then a
133     <directive module="core" type="section">VirtualHost</directive> section
134     should be created for a specified address and port to set the
135     behavior of this virtual host. Note that if the
136     <directive module="core" type="section">VirtualHost</directive>
137     is set for an address and port that the
138     server is not listening to, it cannot be accessed.</p>
139   </section>
140 </manualpage>
141