bind.html revision 57d0156f7bbd9ea3a72342cf9912aba61d118702
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen<html xmlns="http://www.w3.org/1999/xhtml">
ffd9a1898a18fadfc5dce399162c25d50548f905Timo Sirainen <head>
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen <meta name="generator" content="HTML Tidy, see www.w3.org" />
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen <title>Setting which addresses and ports Apache uses</title>
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen </head>
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen vlink="#000080" alink="#FF0000">
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen <!--#include virtual="header.html" -->
8e361d2906b0e44f7175a20981f8d2280645b58bTimo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen <h1 align="CENTER">Setting which addresses and ports Apache
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen uses</h1>
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen <p>When Apache starts, it connects to some port and address on
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen the local machine and waits for incoming requests. By default,
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen it listens to all addresses on the machine, and to the port as
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen specified by the <code>Port</code> directive in the server
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen configuration. However, it can be told to listen to more the
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen one port, or to listen to only selected addresses, or a
221351ed85c839e0b03d82c47654c3d17202e3dbTimo Sirainen combination. This is often combined with the Virtual Host
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen feature which determines how Apache responds to different IP
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen addresses, hostnames and ports.</p>
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen <p>The <code>Listen</code> directive tells the server to accept
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen incoming requests only on the specified port or
19557f192d37cd54a1a090a8a26d9d47265e4413Aki Tuomi address-and-port combinations. If only a port number is
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen specified in the <code>Listen</code> directive, the server
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen listens to the given port on all interfaces, instead of the
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen port given by the <code>Port</code> directive. If an IP address
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen is given as well as a port, the server will listen on the given
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen port and interface. Multiple Listen directives may be used to
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen specify a number of addresses and ports to listen to. The
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen server will respond to requests from any of the listed
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen addresses and ports.</p>
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen <p>For example, to make the server accept connections on both
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen port 80 and port 8000, use:</p>
7ded22760598b78ee29f9418eacc0abe3fb51055Timo Sirainen<pre>
7ded22760598b78ee29f9418eacc0abe3fb51055Timo Sirainen Listen 80
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen Listen 8000
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen</pre>
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen To make the server accept connections on two specified
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen interfaces and port numbers, use
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen<pre>
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen Listen 192.170.2.1:80
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen Listen 192.170.2.5:8000
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen</pre>
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen <h2>How this works with Virtual Hosts</h2>
7ded22760598b78ee29f9418eacc0abe3fb51055Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen <p>Listen does not implement Virtual Hosts. It only tells the
7ded22760598b78ee29f9418eacc0abe3fb51055Timo Sirainen main server what addresses and ports to listen to. If no
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen &lt;VirtualHost&gt; directives are used, the server will behave
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen the same for all accepted requests. However,
8ababf3e7b15f793370d1dedf85825d38b42633fTimo Sirainen &lt;VirtualHost&gt; can be used to specify a different behavior
cfa9359fbd6a967ccdcd553c5e483a093885ab6fTimo Sirainen for one or more of the addresses and ports. To implement a
cfa9359fbd6a967ccdcd553c5e483a093885ab6fTimo Sirainen VirtualHost, the server must first be told to listen to the
cfa9359fbd6a967ccdcd553c5e483a093885ab6fTimo Sirainen address and port to be used. Then a &lt;VirtualHost&gt; section
cfa9359fbd6a967ccdcd553c5e483a093885ab6fTimo Sirainen should be created for a specified address and port to set the
cfa9359fbd6a967ccdcd553c5e483a093885ab6fTimo Sirainen behavior of this virtual host. Note that if the
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen &lt;VirtualHost&gt; is set for an address and port that the
3675a7e9bd3775ba13fe8bc93915902513a0f1a4Timo Sirainen server is not listening to, it cannot be accessed.</p>
3675a7e9bd3775ba13fe8bc93915902513a0f1a4Timo Sirainen
3675a7e9bd3775ba13fe8bc93915902513a0f1a4Timo Sirainen <h2>See also</h2>
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen See also the documentation on <a
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen href="mod/mpm_common.html#listen">Listen directive</a>, <a
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen href="vhosts/">Virtual Hosts</a>, <a
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen href="mod/core.html#port">Port directive</a>, <a
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen href="dns-caveats.html">DNS Issues</a> and <a
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen href="mod/core.html#virtualhost">&lt;VirtualHost&gt;
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen section</a>. <!--#include virtual="footer.html" -->
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen </body>
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen</html>
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen