bind.html.en revision 455a5f75c9935108a7ac1d50996f404e0553ac17
455a5f75c9935108a7ac1d50996f404e0553ac17paul<html><head>
455a5f75c9935108a7ac1d50996f404e0553ac17paul<title>Setting which addresses and ports Apache uses</title>
455a5f75c9935108a7ac1d50996f404e0553ac17paul</head><body>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paul<img src="/images/apache_sub.gif" alt="">
455a5f75c9935108a7ac1d50996f404e0553ac17paul<h1>Setting which addresses and ports Apache uses</h1>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paul<hr>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paulWhen Apache starts, it connects to some port and address on the
455a5f75c9935108a7ac1d50996f404e0553ac17paullocal machine and waits for incoming requests. By default, it
455a5f75c9935108a7ac1d50996f404e0553ac17paullistens to all addresses on the machine, and to the port
455a5f75c9935108a7ac1d50996f404e0553ac17paulas specified by the <tt>Port</tt> directive in the server configuration.
455a5f75c9935108a7ac1d50996f404e0553ac17paulHowever, it can be told to listen to more the one port, or to listen
455a5f75c9935108a7ac1d50996f404e0553ac17paulto only selected addresses, or a combination. This is often combined
455a5f75c9935108a7ac1d50996f404e0553ac17paulwith the Virtual Host feature which determines how Apache
455a5f75c9935108a7ac1d50996f404e0553ac17paulresponds to different IP addresses, hostnames and ports.<p>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paulThere are two directives used to restrict or specify which addresses
455a5f75c9935108a7ac1d50996f404e0553ac17pauland ports Apache listens to.
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paul<ul>
455a5f75c9935108a7ac1d50996f404e0553ac17paul<li><a href="#bindaddress">BindAddress</a> is used to restrict the server to listening to
455a5f75c9935108a7ac1d50996f404e0553ac17paul a single address, and can be used to permit multiple Apache servers
455a5f75c9935108a7ac1d50996f404e0553ac17paul on the same machine listening to different IP addresses.
455a5f75c9935108a7ac1d50996f404e0553ac17paul<li><a href="#listen">Listen</a> can be used to make a single Apache server listen
455a5f75c9935108a7ac1d50996f404e0553ac17paul to more than one address and/or port.
455a5f75c9935108a7ac1d50996f404e0553ac17paul</ul>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paul<h3><a name="bindaddress">BindAddress</a></h3>
455a5f75c9935108a7ac1d50996f404e0553ac17paul<strong>Syntax:</strong> BindAddress <em>[ * | IP-address | hostname ]</em><br>
455a5f75c9935108a7ac1d50996f404e0553ac17paul<strong>Default:</strong> <code>BindAddress *</code><br>
455a5f75c9935108a7ac1d50996f404e0553ac17paul<strong>Context:</strong> server config<br>
455a5f75c9935108a7ac1d50996f404e0553ac17paul<strong>Status:</strong> Core<p>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paulMakes the server listen to just the specified address. If the argument
455a5f75c9935108a7ac1d50996f404e0553ac17paulis *, the server listens to all addresses. The port listened to
455a5f75c9935108a7ac1d50996f404e0553ac17paulis set with the <tt>Port</tt> directive. Only one BindAddress
455a5f75c9935108a7ac1d50996f404e0553ac17paulshould be used.
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paul<h3><a name="listen">Listen</a></h3>
455a5f75c9935108a7ac1d50996f404e0553ac17paul<strong>Syntax:</strong> Listen <em>[ port | IP-address:port ]</em><br>
455a5f75c9935108a7ac1d50996f404e0553ac17paul<strong>Default:</strong> <code>none</code><br>
455a5f75c9935108a7ac1d50996f404e0553ac17paul<strong>Context:</strong> server config<br>
455a5f75c9935108a7ac1d50996f404e0553ac17paul<strong>Status:</strong> Core<p>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paul<tt>Listen</tt> can be used instead of <tt>BindAddress</tt> and
455a5f75c9935108a7ac1d50996f404e0553ac17paul<tt>Port</tt>. It tells the server to accept incoming requests on the
455a5f75c9935108a7ac1d50996f404e0553ac17paulspecified port or address-and-port combination. If the first format is
455a5f75c9935108a7ac1d50996f404e0553ac17paulused, with a port number only, the server listens to the given port on
455a5f75c9935108a7ac1d50996f404e0553ac17paulall interfaces, instead of the port given by the <tt>Port</tt>
455a5f75c9935108a7ac1d50996f404e0553ac17pauldirective. If an IP address is given as well as a port, the server
455a5f75c9935108a7ac1d50996f404e0553ac17paulwill listen on the given port and interface. <p> Multiple Listen
455a5f75c9935108a7ac1d50996f404e0553ac17pauldirectives may be used to specify a number of addresses and ports to
455a5f75c9935108a7ac1d50996f404e0553ac17paullisten to. The server will respond to requests from any of the listed
455a5f75c9935108a7ac1d50996f404e0553ac17pauladdresses and ports.<p>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paulFor example, to make the server accept connections on both port
455a5f75c9935108a7ac1d50996f404e0553ac17paul80 and port 8000, use:
455a5f75c9935108a7ac1d50996f404e0553ac17paul<pre>
455a5f75c9935108a7ac1d50996f404e0553ac17paul Listen 80
455a5f75c9935108a7ac1d50996f404e0553ac17paul Listen 8000
455a5f75c9935108a7ac1d50996f404e0553ac17paul</pre>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paulTo make the server accept connections on two specified
455a5f75c9935108a7ac1d50996f404e0553ac17paulinterfaces and port numbers, use
455a5f75c9935108a7ac1d50996f404e0553ac17paul<pre>
455a5f75c9935108a7ac1d50996f404e0553ac17paul Listen 192.170.2.1:80
455a5f75c9935108a7ac1d50996f404e0553ac17paul Listen 192.170.2.5:8000
455a5f75c9935108a7ac1d50996f404e0553ac17paul</pre>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paul<h2>How this works with Virtual Hosts</h2>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paulBindAddress and Listen do not implement Virtual Hosts. They tell the
455a5f75c9935108a7ac1d50996f404e0553ac17paulmain server what addresses and ports to listen to. If no
455a5f75c9935108a7ac1d50996f404e0553ac17paul&lt;VirtualHost&gt; directives are used, the server will behave the
455a5f75c9935108a7ac1d50996f404e0553ac17paulsame for all accepted requests. However, &lt;VirtualHost&gt; can be
455a5f75c9935108a7ac1d50996f404e0553ac17paulused to specify a different behavour for one or more of the addresses
455a5f75c9935108a7ac1d50996f404e0553ac17pauland ports. To implement a VirtualHost, the server must first be told
455a5f75c9935108a7ac1d50996f404e0553ac17paulto listen to the address and port to be used. Then a
455a5f75c9935108a7ac1d50996f404e0553ac17paul&lt;VirtualHost&gt; section should be created for a specified address
455a5f75c9935108a7ac1d50996f404e0553ac17pauland port to set the behaviour of this virtual host. Note that if the
455a5f75c9935108a7ac1d50996f404e0553ac17paul&lt;VirtualHost&gt; is set for an address and port that the server is
455a5f75c9935108a7ac1d50996f404e0553ac17paulnot listening to, it cannot be accessed.
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paul<h2>See also</h2>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paulSee also the documentation on
455a5f75c9935108a7ac1d50996f404e0553ac17paul<a href="virtual-host.html">Virtual Hosts</a>,
455a5f75c9935108a7ac1d50996f404e0553ac17paul<a href="host.html">Non-IP virtual hosts</a>,
455a5f75c9935108a7ac1d50996f404e0553ac17paul<a href="core.html#bindaddress">BindAddress directive</a>,
455a5f75c9935108a7ac1d50996f404e0553ac17paul<a href="core.html#port">Port directive</a>
455a5f75c9935108a7ac1d50996f404e0553ac17pauland
455a5f75c9935108a7ac1d50996f404e0553ac17paul<a href="core.html#virtualhost">&lt;VirtualHost&gt; section</a>.
455a5f75c9935108a7ac1d50996f404e0553ac17paul</ul>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paul<hr>
455a5f75c9935108a7ac1d50996f404e0553ac17paul<A HREF="../"><IMG SRC="/images/apache_home.gif" ALT="Home"></A>
455a5f75c9935108a7ac1d50996f404e0553ac17paul<A HREF="./"><IMG SRC="/images/apache_index.gif" ALT="Index"></A>
455a5f75c9935108a7ac1d50996f404e0553ac17paul
455a5f75c9935108a7ac1d50996f404e0553ac17paul</BODY>
455a5f75c9935108a7ac1d50996f404e0553ac17paul</HTML>
455a5f75c9935108a7ac1d50996f404e0553ac17paul