bind.html revision 1d3b5af28cfde19db27d714a43cb6e5109ec1b2d
458N/A<html><head>
458N/A<title>Setting which addresses and ports Apache uses</title>
458N/A</head><body>
458N/A
458N/A<!--#include virtual="header.html" -->
458N/A<h1>Setting which addresses and ports Apache uses</h1>
458N/A
458N/A<hr>
458N/A
458N/AWhen Apache starts, it connects to some port and address on the
458N/Alocal machine and waits for incoming requests. By default, it
458N/Alistens to all addresses on the machine, and to the port
458N/Aas specified by the <tt>Port</tt> directive in the server configuration.
458N/AHowever, it can be told to listen to more the one port, or to listen
458N/Ato only selected addresses, or a combination. This is often combined
458N/Awith the Virtual Host feature which determines how Apache
458N/Aresponds to different IP addresses, hostnames and ports.<p>
458N/A
458N/AThere are two directives used to restrict or specify which addresses
458N/Aand ports Apache listens to.
814N/A
458N/A<ul>
458N/A<li><a href="#bindaddress">BindAddress</a> is used to restrict the server to listening to
458N/A a single address, and can be used to permit multiple Apache servers
458N/A on the same machine listening to different IP addresses.
458N/A<li><a href="#listen">Listen</a> can be used to make a single Apache server listen
458N/A to more than one address and/or port.
458N/A</ul>
952N/A
618N/A<h3><a name="bindaddress">BindAddress</a></h3>
458N/A<strong>Syntax:</strong> BindAddress <em>[ * | IP-address | hostname ]</em><br>
458N/A<strong>Default:</strong> <code>BindAddress *</code><br>
844N/A<strong>Context:</strong> server config<br>
952N/A<strong>Status:</strong> Core<p>
618N/A
1273N/AMakes the server listen to just the specified address. If the argument
458N/Ais *, the server listens to all addresses. The port listened to
458N/Ais set with the <tt>Port</tt> directive. Only one BindAddress
458N/Ashould be used.
458N/A
581N/A<h3><a name="listen">Listen</a></h3>
458N/A<strong>Syntax:</strong> Listen <em>[ port | IP-address:port ]</em><br>
458N/A<strong>Default:</strong> <code>none</code><br>
458N/A<strong>Context:</strong> server config<br>
458N/A<strong>Status:</strong> Core<p>
458N/A
969N/A<tt>Listen</tt> can be used instead of <tt>BindAddress</tt> and
969N/A<tt>Port</tt>. It tells the server to accept incoming requests on the
969N/Aspecified port or address-and-port combination. If the first format is
969N/Aused, with a port number only, the server listens to the given port on
969N/Aall interfaces, instead of the port given by the <tt>Port</tt>
969N/Adirective. If an IP address is given as well as a port, the server
969N/Awill listen on the given port and interface. <p> Multiple Listen
458N/Adirectives may be used to specify a number of addresses and ports to
458N/Alisten to. The server will respond to requests from any of the listed
969N/Aaddresses and ports.<p>
969N/A
458N/AFor example, to make the server accept connections on both port
458N/A80 and port 8000, use:
458N/A<pre>
458N/A Listen 80
458N/A Listen 8000
458N/A</pre>
458N/A
458N/ATo make the server accept connections on two specified
458N/Ainterfaces and port numbers, use
458N/A<pre>
646N/A Listen 192.170.2.1:80
646N/A Listen 192.170.2.5:8000
646N/A</pre>
646N/A
646N/A<h2>How this works with Virtual Hosts</h2>
646N/A
646N/ABindAddress and Listen do not implement Virtual Hosts. They tell the
814N/Amain server what addresses and ports to listen to. If no
814N/A&lt;VirtualHost&gt; directives are used, the server will behave the
814N/Asame for all accepted requests. However, &lt;VirtualHost&gt; can be
814N/Aused to specify a different behavour for one or more of the addresses
814N/Aand ports. To implement a VirtualHost, the server must first be told
814N/Ato listen to the address and port to be used. Then a
646N/A&lt;VirtualHost&gt; section should be created for a specified address
646N/Aand port to set the behavior of this virtual host. Note that if the
646N/A&lt;VirtualHost&gt; is set for an address and port that the server is
646N/Anot listening to, it cannot be accessed.
458N/A
458N/A<h2>See also</h2>
458N/A
458N/ASee also the documentation on
458N/A<a href="virtual-host.html">Virtual Hosts</a>,
581N/A<a href="host.html">Non-IP virtual hosts</a>,
581N/A<a href="mod/core.html#bindaddress">BindAddress directive</a>,
581N/A<a href="mod/core.html#port">Port directive</a>,
458N/A<a href="dns-caveats.html">DNS Issues</a>
458N/Aand
458N/A<a href="mod/core.html#virtualhost">&lt;VirtualHost&gt; section</a>.
458N/A</ul>
458N/A
458N/A<!--#include virtual="footer.html" -->
458N/A</BODY>
458N/A</HTML>
458N/A
458N/A