bind.html revision bf3d9f591e5af24fdcaa9029094dc045878d1d1a
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<html><head>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<title>Setting which addresses and ports Apache uses</title>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony</head>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<BODY
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen BGCOLOR="#FFFFFF"
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony TEXT="#000000"
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony LINK="#0000FF"
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen VLINK="#000080"
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen ALINK="#FF0000"
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen>
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<!--#include virtual="header.html" -->
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<h1 ALIGN="CENTER">Setting which addresses and ports Apache uses</h1>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen<hr>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyWhen Apache starts, it connects to some port and address on the
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonylocal machine and waits for incoming requests. By default, it
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonylistens to all addresses on the machine, and to the port
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowenas specified by the <tt>Port</tt> directive in the server configuration.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyHowever, it can be told to listen to more the one port, or to listen
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyto only selected addresses, or a combination. This is often combined
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonywith the Virtual Host feature which determines how Apache
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyresponds to different IP addresses, hostnames and ports.<p>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyThere are two directives used to restrict or specify which addresses
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyand ports Apache listens to.
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<ul>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<li><a href="#bindaddress">BindAddress</a> is used to restrict the server to listening to
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen a single address, and can be used to permit multiple Apache servers
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen on the same machine listening to different IP addresses.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<li><a href="#listen">Listen</a> can be used to make a single Apache server listen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen to more than one address and/or port.
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen</ul>
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<h3><a name="bindaddress">BindAddress</a></h3>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<strong>Syntax:</strong> BindAddress <em>[ * | IP-address | hostname ]</em><br>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<strong>Default:</strong> <code>BindAddress *</code><br>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<strong>Context:</strong> server config<br>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<strong>Status:</strong> Core<p>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyMakes the server listen to just the specified address. If the argument
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedoohis *, the server listens to all addresses. The port listened to
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyis set with the <tt>Port</tt> directive. Only one BindAddress
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyshould be used.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<h3><a name="listen">Listen</a></h3>
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen<strong>Syntax:</strong> Listen <em>[ port | IP-address:port ]</em><br>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<strong>Default:</strong> <code>none</code><br>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<strong>Context:</strong> server config<br>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<strong>Status:</strong> Core<p>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<tt>Listen</tt> can be used instead of <tt>BindAddress</tt> and
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<tt>Port</tt>. It tells the server to accept incoming requests on the
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyspecified port or address-and-port combination. If the first format is
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyused, with a port number only, the server listens to the given port on
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyall interfaces, instead of the port given by the <tt>Port</tt>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonydirective. If an IP address is given as well as a port, the server
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonywill listen on the given port and interface. <p> Multiple Listen
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonydirectives may be used to specify a number of addresses and ports to
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonylisten to. The server will respond to requests from any of the listed
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyaddresses and ports.<p>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyFor example, to make the server accept connections on both port
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony80 and port 8000, use:
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<pre>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony Listen 80
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony Listen 8000
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony</pre>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyTo make the server accept connections on two specified
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyinterfaces and port numbers, use
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<pre>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony Listen 192.170.2.1:80
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony Listen 192.170.2.5:8000
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony</pre>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<h2>How this works with Virtual Hosts</h2>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyBindAddress and Listen do not implement Virtual Hosts. They tell the
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonymain server what addresses and ports to listen to. If no
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony&lt;VirtualHost&gt; directives are used, the server will behave the
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonysame for all accepted requests. However, &lt;VirtualHost&gt; can be
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyused to specify a different behavior for one or more of the addresses
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyand ports. To implement a VirtualHost, the server must first be told
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyto listen to the address and port to be used. Then a
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony&lt;VirtualHost&gt; section should be created for a specified address
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyand port to set the behavior of this virtual host. Note that if the
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony&lt;VirtualHost&gt; is set for an address and port that the server is
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonynot listening to, it cannot be accessed.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<h2>See also</h2>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonySee also the documentation on
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<a href="virtual-host.html">Virtual Hosts</a>,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<a href="host.html">Non-IP virtual hosts</a>,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<a href="mod/core.html#bindaddress">BindAddress directive</a>,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<a href="mod/core.html#port">Port directive</a>,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<a href="dns-caveats.html">DNS Issues</a>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyand
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<a href="mod/core.html#virtualhost">&lt;VirtualHost&gt; section</a>.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<!--#include virtual="footer.html" -->
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony</BODY>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony</HTML>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony