bind.html revision bf3d9f591e5af24fdcaa9029094dc045878d1d1a
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<title>Setting which addresses and ports Apache uses</title>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen BGCOLOR="#FFFFFF"
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony TEXT="#000000"
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony LINK="#0000FF"
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen VLINK="#000080"
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen ALINK="#FF0000"
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<!--#include virtual="header.html" -->
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<h1 ALIGN="CENTER">Setting which addresses and ports Apache uses</h1>
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>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyThere are two directives used to restrict or specify which addresses
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyand ports Apache listens to.
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
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<strong>Syntax:</strong> BindAddress <em>[ * | IP-address | hostname ]</em><br>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<strong>Default:</strong> <code>BindAddress *</code><br>
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.
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen<strong>Syntax:</strong> Listen <em>[ port | IP-address:port ]</em><br>
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>
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyFor example, to make the server accept connections on both port
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony80 and port 8000, use:
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony Listen 8000
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyTo make the server accept connections on two specified
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyinterfaces and port numbers, use
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony Listen 192.170.2.1:80
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony Listen 192.170.2.5:8000
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyBindAddress and Listen do not implement Virtual Hosts. They tell the
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonymain server what addresses and ports to listen to. If no
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<VirtualHost> directives are used, the server will behave the
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonysame for all accepted requests. However, <VirtualHost> 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<VirtualHost> section should be created for a specified address
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyand port to set the behavior of this virtual host. Note that if the
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<VirtualHost> is set for an address and port that the server is
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonynot listening to, it cannot be accessed.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonySee also the documentation on
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<a href="mod/core.html#bindaddress">BindAddress directive</a>,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<a href="mod/core.html#virtualhost"><VirtualHost> section</a>.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony<!--#include virtual="footer.html" -->