bind.html revision e507b318e2b8f7f6a749b9fba35b1b65b560eacc
d3ed5b56cb6b58f87ffd125bed48f7668f13de1edirkx<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
893328ef6ff86d0ca27774778d84410353789fb0fielding<html><head>
842ae4bd224140319ae7feec1872b93dfd491143fielding<title>Setting which addresses and ports Apache uses</title>
842ae4bd224140319ae7feec1872b93dfd491143fielding</head>
842ae4bd224140319ae7feec1872b93dfd491143fielding
842ae4bd224140319ae7feec1872b93dfd491143fielding<BODY BGCOLOR="white" TEXT="black" LINK="blue" VLINK="navy" ALINK="red">
842ae4bd224140319ae7feec1872b93dfd491143fielding<!--#include virtual="header.html" -->
842ae4bd224140319ae7feec1872b93dfd491143fielding<h1 ALIGN="CENTER">Setting which addresses and ports Apache uses</h1>
893328ef6ff86d0ca27774778d84410353789fb0fielding
0202d2114cc6d7042995100519cce45c808c153bnd<hr>
893328ef6ff86d0ca27774778d84410353789fb0fielding
0202d2114cc6d7042995100519cce45c808c153bndWhen Apache starts, it connects to some port and address on the
0202d2114cc6d7042995100519cce45c808c153bndlocal machine and waits for incoming requests. By default, it
0202d2114cc6d7042995100519cce45c808c153bndlistens to all addresses on the machine, and to the port
0202d2114cc6d7042995100519cce45c808c153bndas specified by the <tt>Port</tt> directive in the server configuration.
0202d2114cc6d7042995100519cce45c808c153bndHowever, it can be told to listen to more the one port, or to listen
893328ef6ff86d0ca27774778d84410353789fb0fieldingto only selected addresses, or a combination. This is often combined
893328ef6ff86d0ca27774778d84410353789fb0fieldingwith the Virtual Host feature which determines how Apache
893328ef6ff86d0ca27774778d84410353789fb0fieldingresponds to different IP addresses, hostnames and ports.<p>
893328ef6ff86d0ca27774778d84410353789fb0fielding
0d50a692ff2ac7bdb42e417737ed86ebf0a41671benThere are two directives used to restrict or specify which addresses
14eccd0082c748ae3464dc2459430ff0772b5107sfand ports Apache listens to.
14eccd0082c748ae3464dc2459430ff0772b5107sf
14eccd0082c748ae3464dc2459430ff0772b5107sf<ul>
14eccd0082c748ae3464dc2459430ff0772b5107sf<li><a href="#bindaddress">BindAddress</a> is used to restrict the server to listening to
14eccd0082c748ae3464dc2459430ff0772b5107sf a single address, and can be used to permit multiple Apache servers
14eccd0082c748ae3464dc2459430ff0772b5107sf on the same machine listening to different IP addresses.
14eccd0082c748ae3464dc2459430ff0772b5107sf<li><a href="#listen">Listen</a> can be used to make a single Apache server listen
14eccd0082c748ae3464dc2459430ff0772b5107sf to more than one address and/or port.
14eccd0082c748ae3464dc2459430ff0772b5107sf</ul>
14eccd0082c748ae3464dc2459430ff0772b5107sf
14eccd0082c748ae3464dc2459430ff0772b5107sf<h3><a name="bindaddress">BindAddress</a></h3>
14eccd0082c748ae3464dc2459430ff0772b5107sf<strong>Syntax:</strong> BindAddress <em>[ * | IP-address | hostname ]</em><br>
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<strong>Default:</strong> <code>BindAddress *</code><br>
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<strong>Context:</strong> server config<br>
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<strong>Status:</strong> Core<p>
90b402e944318ae02afd50911eae6da1910f661dpquerna
928f622b54e87afbbaba6add8aef8066ca16a040wroweMakes the server listen to just the specified address. If the argument
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzis *, the server listens to all addresses. The port listened to
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzis set with the <tt>Port</tt> directive. Only one BindAddress
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzshould be used.
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<h3><a name="listen">Listen</a></h3>
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<strong>Syntax:</strong> Listen <em>[ port | IP-address:port ]</em><br>
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<strong>Default:</strong> <code>none</code><br>
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<strong>Context:</strong> server config<br>
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<strong>Status:</strong> Core<p>
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<tt>Listen</tt> can be used instead of <tt>BindAddress</tt> and
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<tt>Port</tt>. It tells the server to accept incoming requests on the
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzspecified port or address-and-port combination. If the first format is
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzused, with a port number only, the server listens to the given port on
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzall interfaces, instead of the port given by the <tt>Port</tt>
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzdirective. If an IP address is given as well as a port, the server
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzwill listen on the given port and interface. <p> Multiple Listen
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzdirectives may be used to specify a number of addresses and ports to
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzlisten to. The server will respond to requests from any of the listed
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzaddresses and ports.<p>
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzFor example, to make the server accept connections on both port
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz80 and port 8000, use:
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<pre>
893328ef6ff86d0ca27774778d84410353789fb0fielding Listen 80
893328ef6ff86d0ca27774778d84410353789fb0fielding Listen 8000
893328ef6ff86d0ca27774778d84410353789fb0fielding</pre>
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz
0b7037d0efc1cd510ee12e8a35c982c3f2da0353pquernaTo make the server accept connections on two specified
90b402e944318ae02afd50911eae6da1910f661dpquernainterfaces and port numbers, use
90b402e944318ae02afd50911eae6da1910f661dpquerna<pre>
a9de7b69548bd69bfc84e9eea6a8215db2640deftakashi Listen 192.170.2.1:80
0b7037d0efc1cd510ee12e8a35c982c3f2da0353pquerna Listen 192.170.2.5:8000
90b402e944318ae02afd50911eae6da1910f661dpquerna</pre>
90b402e944318ae02afd50911eae6da1910f661dpquerna
c5694b1d7dca4f561ebce416b5ffacf856f825aawrowe<h2>How this works with Virtual Hosts</h2>
90b402e944318ae02afd50911eae6da1910f661dpquerna
90b402e944318ae02afd50911eae6da1910f661dpquernaBindAddress and Listen do not implement Virtual Hosts. They tell the
90b402e944318ae02afd50911eae6da1910f661dpquernamain server what addresses and ports to listen to. If no
90b402e944318ae02afd50911eae6da1910f661dpquerna&lt;VirtualHost&gt; directives are used, the server will behave the
90b402e944318ae02afd50911eae6da1910f661dpquernasame for all accepted requests. However, &lt;VirtualHost&gt; can be
90b402e944318ae02afd50911eae6da1910f661dpquernaused to specify a different behavior for one or more of the addresses
90b402e944318ae02afd50911eae6da1910f661dpquernaand ports. To implement a VirtualHost, the server must first be told
90b402e944318ae02afd50911eae6da1910f661dpquernato listen to the address and port to be used. Then a
893328ef6ff86d0ca27774778d84410353789fb0fielding&lt;VirtualHost&gt; section should be created for a specified address
90b402e944318ae02afd50911eae6da1910f661dpquernaand port to set the behavior of this virtual host. Note that if the
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz&lt;VirtualHost&gt; is set for an address and port that the server is
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantznot listening to, it cannot be accessed.
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz
893328ef6ff86d0ca27774778d84410353789fb0fielding<h2>See also</h2>
f14fe1f44cb7018927ee0e31eb959cba8dc3700bjorton
893328ef6ff86d0ca27774778d84410353789fb0fieldingSee also the documentation on
0b7037d0efc1cd510ee12e8a35c982c3f2da0353pquerna<a href="virtual-host.html">Virtual Hosts</a>,
eb06d6a7dc2a6609217689ee5e430d87637ef9e6rpluem<a href="host.html">Non-IP virtual hosts</a>,
eb06d6a7dc2a6609217689ee5e430d87637ef9e6rpluem<a href="mod/core.html#bindaddress">BindAddress directive</a>,
eb06d6a7dc2a6609217689ee5e430d87637ef9e6rpluem<a href="mod/core.html#port">Port directive</a>,
893328ef6ff86d0ca27774778d84410353789fb0fielding<a href="dns-caveats.html">DNS Issues</a>
90b402e944318ae02afd50911eae6da1910f661dpquernaand
eb06d6a7dc2a6609217689ee5e430d87637ef9e6rpluem<a href="mod/core.html#virtualhost">&lt;VirtualHost&gt; section</a>.
eb06d6a7dc2a6609217689ee5e430d87637ef9e6rpluem
eb06d6a7dc2a6609217689ee5e430d87637ef9e6rpluem<!--#include virtual="footer.html" -->
eb06d6a7dc2a6609217689ee5e430d87637ef9e6rpluem</BODY>
eb06d6a7dc2a6609217689ee5e430d87637ef9e6rpluem</HTML>
90b402e944318ae02afd50911eae6da1910f661dpquerna
90b402e944318ae02afd50911eae6da1910f661dpquerna