]> granicus.if.org Git - apache/blob - docs/manual/bind.html.en
Documentation appearance rework, pass 1, phase 1: background,
[apache] / docs / manual / bind.html.en
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <html><head>
3 <title>Setting which addresses and ports Apache uses</title>
4 </head>
5
6 <BODY BGCOLOR="white" TEXT="black" LINK="blue" VLINK="navy" ALINK="red">
7 <!--#include virtual="header.html" -->
8 <h1 ALIGN="CENTER">Setting which addresses and ports Apache uses</h1>
9
10 <hr>
11
12 When Apache starts, it connects to some port and address on the
13 local machine and waits for incoming requests. By default, it
14 listens to all addresses on the machine, and to the port
15 as specified by the <tt>Port</tt> directive in the server configuration.
16 However, it can be told to listen to more the one port, or to listen
17 to only selected addresses, or a combination. This is often combined
18 with the Virtual Host feature which determines how Apache
19 responds to different IP addresses, hostnames and ports.<p>
20
21 There are two directives used to restrict or specify which addresses
22 and ports Apache listens to.
23
24 <ul>
25 <li><a href="#bindaddress">BindAddress</a> is used to restrict the server to listening to
26   a single address, and can be used to permit multiple Apache servers
27   on the same machine listening to different IP addresses.
28 <li><a href="#listen">Listen</a> can be used to make a single Apache server listen
29   to more than one address and/or port.
30 </ul>
31
32 <h3><a name="bindaddress">BindAddress</a></h3>
33 <strong>Syntax:</strong> BindAddress <em>[ * | IP-address | hostname ]</em><br>
34 <strong>Default:</strong> <code>BindAddress *</code><br>
35 <strong>Context:</strong> server config<br>
36 <strong>Status:</strong> Core<p>
37
38 Makes the server listen to just the specified address. If the argument
39 is *, the server listens to all addresses. The port listened to
40 is set with the <tt>Port</tt> directive. Only one BindAddress
41 should be used.
42
43 <h3><a name="listen">Listen</a></h3>
44 <strong>Syntax:</strong> Listen <em>[ port | IP-address:port ]</em><br>
45 <strong>Default:</strong> <code>none</code><br>
46 <strong>Context:</strong> server config<br>
47 <strong>Status:</strong> Core<p>
48
49 <tt>Listen</tt> can be used instead of <tt>BindAddress</tt> and
50 <tt>Port</tt>. It tells the server to accept incoming requests on the
51 specified port or address-and-port combination. If the first format is
52 used, with a port number only, the server listens to the given port on
53 all interfaces, instead of the port given by the <tt>Port</tt>
54 directive. If an IP address is given as well as a port, the server
55 will listen on the given port and interface.  <p> Multiple Listen
56 directives may be used to specify a number of addresses and ports to
57 listen to. The server will respond to requests from any of the listed
58 addresses and ports.<p>
59
60 For example, to make the server accept connections on both port
61 80 and port 8000, use:
62 <pre>
63    Listen 80
64    Listen 8000
65 </pre>
66
67 To make the server accept connections on two specified
68 interfaces and port numbers, use
69 <pre>
70    Listen 192.170.2.1:80
71    Listen 192.170.2.5:8000
72 </pre>
73
74 <h2>How this works with Virtual Hosts</h2>
75
76 BindAddress and Listen do not implement Virtual Hosts. They tell the
77 main server what addresses and ports to listen to.  If no
78 &lt;VirtualHost&gt; directives are used, the server will behave the
79 same for all accepted requests. However, &lt;VirtualHost&gt; can be
80 used to specify a different behavior for one or more of the addresses
81 and ports. To implement a VirtualHost, the server must first be told
82 to listen to the address and port to be used. Then a
83 &lt;VirtualHost&gt; section should be created for a specified address
84 and port to set the behavior of this virtual host. Note that if the
85 &lt;VirtualHost&gt; is set for an address and port that the server is
86 not listening to, it cannot be accessed.
87
88 <h2>See also</h2>
89
90 See also the documentation on
91 <a href="virtual-host.html">Virtual Hosts</a>,
92 <a href="host.html">Non-IP virtual hosts</a>,
93 <a href="mod/core.html#bindaddress">BindAddress directive</a>,
94 <a href="mod/core.html#port">Port directive</a>,
95 <a href="dns-caveats.html">DNS Issues</a>
96 and
97 <a href="mod/core.html#virtualhost">&lt;VirtualHost&gt; section</a>.
98
99 <!--#include virtual="footer.html" -->
100 </BODY>
101 </HTML>
102