]> granicus.if.org Git - apache/blob - docs/manual/bind.html.en
Patch submitted by David Shane Holden to make docs valid xhtml.
[apache] / docs / manual / bind.html.en
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
4 <html xmlns="http://www.w3.org/1999/xhtml">
5   <head>
6     <meta name="generator" content="HTML Tidy, see www.w3.org" />
7
8     <title>Setting which addresses and ports Apache uses</title>
9   </head>
10   <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
11
12   <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
13   vlink="#000080" alink="#FF0000">
14     <!--#include virtual="header.html" -->
15
16     <h1 align="center">Setting which addresses and ports Apache
17     uses</h1>
18
19     <p>When Apache starts, it connects to some port and address on
20     the local machine and waits for incoming requests. By default,
21     it listens to all addresses on the machine.  However, it needs to
22     be told to listen to specific ports, or to listen to only selected 
23     addresses, or a combination. This is often combined with the 
24     Virtual Host feature which determines how Apache responds to 
25     different IP addresses, hostnames and ports.</p>
26
27     <p>The <code>Listen</code> directive tells the server to accept
28     incoming requests only on the specified port or
29     address-and-port combinations. If only a port number is
30     specified in the <code>Listen</code> directive, the server
31     listens to the given port on all interfaces. If an IP address
32     is given as well as a port, the server will listen on the given
33     port and interface. Multiple Listen directives may be used to
34     specify a number of addresses and ports to listen to. The
35     server will respond to requests from any of the listed
36     addresses and ports.</p>
37
38     <p>For example, to make the server accept connections on both
39     port 80 and port 8000, use:</p>
40 <pre>
41    Listen 80
42    Listen 8000
43 </pre>
44     To make the server accept connections on two specified
45     interfaces and port numbers, use 
46 <pre>
47    Listen 192.170.2.1:80
48    Listen 192.170.2.5:8000
49 </pre>
50     IPv6 addresses must be surrounded in square brackets, as in the
51     following example:
52 <pre>
53    Listen [fe80::a00:20ff:fea7:ccea]:80
54 </pre>
55
56     <h2>Special IPv6 considerations</h2>
57
58     When APR supports IPv6, Apache will create IPv6-capable listening
59     sockets by default (i.e., when no IP address is specified on the
60     Listen directive).  In other words, when APR supports IPv6,
61 <pre>
62    Listen 80
63 </pre>
64     is equivalent to 
65 <pre>
66    Listen [::]:80
67 </pre>
68     When APR does not support IPv6,
69 <pre>
70    Listen 80
71 </pre>
72     is equivalent to
73 <pre>
74    Listen 0.0.0.0:80
75 </pre>
76     On some platforms, such as NetBSD, binding to the IPv6 wildcard address 
77     ("::") does not allow Apache to accept connections on IPv4 interfaces.
78     In this situation, multiple Listen directives are required, as shown
79     below:
80 <pre>
81    Listen 0.0.0.0:80
82    Listen [::]:80
83 </pre>
84     Apache does not currently detect this, so the Listen statements must
85     be edited manually by the administrator.
86
87     <h2>How this works with Virtual Hosts</h2>
88
89     <p>Listen does not implement Virtual Hosts. It only tells the
90     main server what addresses and ports to listen to. If no
91     &lt;VirtualHost&gt; directives are used, the server will behave
92     the same for all accepted requests. However,
93     &lt;VirtualHost&gt; can be used to specify a different behavior
94     for one or more of the addresses and ports. To implement a
95     VirtualHost, the server must first be told to listen to the
96     address and port to be used. Then a &lt;VirtualHost&gt; section
97     should be created for a specified address and port to set the
98     behavior of this virtual host. Note that if the
99     &lt;VirtualHost&gt; is set for an address and port that the
100     server is not listening to, it cannot be accessed.</p>
101
102     <h2>See also</h2>
103     See also the documentation on <a
104     href="mod/mpm_common.html#listen">Listen directive</a>, <a
105     href="vhosts/">Virtual Hosts</a>, <a
106     href="dns-caveats.html">DNS Issues</a> and <a
107     href="mod/core.html#virtualhost">&lt;VirtualHost&gt;
108     section</a>. <!--#include virtual="footer.html" -->
109   </body>
110 </html>
111