summaryrefslogtreecommitdiff
path: root/docs/manual/bind.xml
blob: 4f342ee06a6d1e6efdad315545f0e32b8009dccc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
<?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>

<manualpage>
  <relativepath href="."/>

  <title>Binding</title>

  <summary>
    <p>Configuring Apache to listen on specific addresses and ports.</p>
  </summary>
  
  <seealso><a href="vhosts/">Virtual Hosts</a></seealso>
  <seealso><a href="dns-caveats.html">DNS Issues</a></seealso>

  <section id="overview">
    <title>Overview</title>
    
    <related>
      <modulelist>
        <module>core</module>
        <module>mpm_common</module>
      </modulelist>
      <directivelist>
        <directive module="core">VirtualHost</directive>
        <directive module="mpm_common">Listen</directive>
      </directivelist>
    </related>
    
    
    <p>When Apache starts, it binds to some port and address on
    the local machine and waits for incoming requests. By default,
    it listens to all addresses on the machine.  However, it needs to
    be told to listen on specific ports, or to listen on only selected 
    addresses, or a combination. This is often combined with the 
    Virtual Host feature which determines how Apache responds to 
    different IP addresses, hostnames and ports.</p>

    <p>The <directive module="mpm_common">Listen</directive>
    directive tells the server to accept
    incoming requests only on the specified port or
    address-and-port combinations. If only a port number is
    specified in the <directive module="mpm_common">Listen</directive>
    directive, the server
    listens to the given port on all interfaces. If an IP address
    is given as well as a port, the server will listen on the given
    port and interface. Multiple Listen directives may be used to
    specify a number of addresses and ports to listen on. The
    server will respond to requests from any of the listed
    addresses and ports.</p>

    <p>For example, to make the server accept connections on both
    port 80 and port 8000, use:</p>

    <example>
      Listen 80<br />
      Listen 8000
    </example>

    <p>To make the server accept connections on two specified
    interfaces and port numbers, use</p>

    <example>
      Listen 192.170.2.1:80<br />
      Listen 192.170.2.5:8000
    </example>

    <p>IPv6 addresses must be surrounded in square brackets, as in the
    following example:</p>

    <example>
      Listen [fe80::a00:20ff:fea7:ccea]:80
    </example>
  </section>

  <section id="ipv6">
    <title>Special IPv6 Considerations</title>

    <p>When APR supports IPv6, Apache will create IPv6-capable listening
    sockets by default (i.e., when no IP address is specified on the
    Listen directive).  In other words, when APR supports IPv6,</p>

    <example>
      Listen 80
    </example>

    <p>is equivalent to</p>

    <example>
      Listen [::]:80
    </example>

    <p>When APR does not support IPv6,</p>

    <example>
      Listen 80
    </example>

    <p>is equivalent to</p>

    <example>
      Listen 0.0.0.0:80
    </example>

    <p>On some platforms, such as NetBSD, binding to the IPv6 wildcard address 
    ("::") does not allow Apache to accept connections on IPv4 interfaces.
    In this situation, multiple Listen directives are required, as shown
    below:</p>

    <example>
      Listen 0.0.0.0:80<br />
      Listen [::]:0
    </example>

    <p>Apache does not currently detect this, so the Listen statements must
    be edited manually by the administrator.</p>
  </section>

  <section id="virtualhost">
    <title>How This Works With Virtual Hosts</title>

    <p>Listen does not implement Virtual Hosts. It only tells the
    main server what addresses and ports to listen to. If no
    <directive module="core" type="section">VirtualHost</directive>
    directives are used, the server will behave
    the same 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 and 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 a 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>