ip-based.html revision dd2cbf08558860773e4afc8d4f8cce3d85d77f58
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<html>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<head>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<title>Apache IP-based Virtual Host Support</title>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan</head>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<BODY
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan BGCOLOR="#FFFFFF"
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan TEXT="#000000"
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan LINK="#0000FF"
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan VLINK="#000080"
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan ALINK="#FF0000"
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<!--#include virtual="header.html" -->
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<h1 ALIGN="CENTER">Apache IP-based Virtual Host Support</h1>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<strong>See also:</strong>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<a href="name-based.html">Name-based Virtual Hosts Support</a>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<HR>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<h2>System requirements</h2>
305373bfa854723d80c740a2ff9d277d0f34082aHarry PanAs the term <cite>IP-based</cite> indicates, the server <strong>must have a
b4a94e1e9bfb77dcba635f9e3cfd4fd4276b64ccLubos Koscodifferent IP address for each IP-based virtual host</strong>.
b4a94e1e9bfb77dcba635f9e3cfd4fd4276b64ccLubos KoscoThis can be achieved by the machine having several physical network connections,
305373bfa854723d80c740a2ff9d277d0f34082aHarry Panor by use of virtual interfaces which are supported by most modern
b4a94e1e9bfb77dcba635f9e3cfd4fd4276b64ccLubos Koscooperating systems (see system documentation for details, these are
305373bfa854723d80c740a2ff9d277d0f34082aHarry Panfrequently called "ip aliases", and the "ifconfig" command
b4a94e1e9bfb77dcba635f9e3cfd4fd4276b64ccLubos Koscois most commonly used to set them up).
b4a94e1e9bfb77dcba635f9e3cfd4fd4276b64ccLubos Kosco
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<h2>How to set up Apache</h2>
305373bfa854723d80c740a2ff9d277d0f34082aHarry PanThere are two ways of configuring apache to support multiple hosts.
305373bfa854723d80c740a2ff9d277d0f34082aHarry PanEither by running a separate httpd daemon for each hostname, or by running a
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pansingle daemon which supports all the virtual hosts.
b4a94e1e9bfb77dcba635f9e3cfd4fd4276b64ccLubos Kosco<p>
305373bfa854723d80c740a2ff9d277d0f34082aHarry PanUse multiple daemons when:
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<ul>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<li>The different virtual hosts need very different httpd configurations, such
b4a94e1e9bfb77dcba635f9e3cfd4fd4276b64ccLubos Kosco as different values for: <A HREF="/mod/core.html#servertype">ServerType</A>,
98bcd7b17c979c7394ffc18d7c052a0b5602208eJHKST <A HREF="/mod/core.html#user">User</A>,
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan <A HREF="/mod/core.html#group">Group</A>,
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan <A HREF="/mod/mod_mime.html#typesconfig">TypesConfig</A> or
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan <A HREF="/mod/core.html#serverroot">ServerRoot</A>.
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<li>The machine does not process a very high request rate.
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan</ul>
305373bfa854723d80c740a2ff9d277d0f34082aHarry PanUse a single daemon when:
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<ul>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<li>Sharing of the httpd configuration between virtual hosts is acceptable.
98bcd7b17c979c7394ffc18d7c052a0b5602208eJHKST<li>The machine services a large number of requests, and so the performance
98bcd7b17c979c7394ffc18d7c052a0b5602208eJHKST loss in running separate daemons may be significant.
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan</ul>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<h2>Setting up multiple daemons</h2>
305373bfa854723d80c740a2ff9d277d0f34082aHarry PanCreate a separate httpd installation for each virtual host.
305373bfa854723d80c740a2ff9d277d0f34082aHarry PanFor each installation, use the
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<A HREF="/mod/core.html#listen">Listen</A> directive in the configuration
305373bfa854723d80c740a2ff9d277d0f34082aHarry Panfile to select which IP address (or virtual host) that daemon services.
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pane.g.
584eb5925eab183765dfba2c839a31304c9eb8f6Lubos Kosco<pre>
584eb5925eab183765dfba2c839a31304c9eb8f6Lubos Kosco Listen www.smallco.com:80
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan</pre>
305373bfa854723d80c740a2ff9d277d0f34082aHarry PanIt is recommended that you use an IP address instead of a hostname
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan(see <A HREF="/dns-caveats.html">DNS page</A>).
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<h2>Setting up a single daemon with virtual hosts</h2>
305373bfa854723d80c740a2ff9d277d0f34082aHarry PanFor this case, a single httpd will service requests for the main server
305373bfa854723d80c740a2ff9d277d0f34082aHarry Panand all the virtual hosts.
305373bfa854723d80c740a2ff9d277d0f34082aHarry PanThe <A HREF="/mod/core.html#virtualhost">VirtualHost</A> directive in the
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan configuration file is used to set the values of
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<A HREF="/mod/core.html#serveradmin">ServerAdmin</A>,
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<A HREF="/mod/core.html#servername">ServerName</A>,
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<A HREF="/mod/core.html#documentroot">DocumentRoot</A>,
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<A HREF="/mod/core.html#errorlog">ErrorLog</A> and
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<A HREF="/mod/mod_log_config.html#transferlog">TransferLog</A> or
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<A HREF="/mod/mod_log_config.html#customlog">CustomLog</A>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Panconfiguration directives to different values for each virtual host.
eb1776903fd1f998009e97470a65fba8a499a0d9Lubos Koscoe.g.
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan<pre>
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan &lt;VirtualHost www.smallco.com&gt;
98bcd7b17c979c7394ffc18d7c052a0b5602208eJHKST ServerAdmin webmaster@mail.smallco.com
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan DocumentRoot /groups/smallco/www
eb1776903fd1f998009e97470a65fba8a499a0d9Lubos Kosco ServerName www.smallco.com
eb1776903fd1f998009e97470a65fba8a499a0d9Lubos Kosco ErrorLog /groups/smallco/logs/error_log
eb1776903fd1f998009e97470a65fba8a499a0d9Lubos Kosco TransferLog /groups/smallco/logs/access_log
eb1776903fd1f998009e97470a65fba8a499a0d9Lubos Kosco &lt;/VirtualHost&gt;
eb1776903fd1f998009e97470a65fba8a499a0d9Lubos Kosco
eb1776903fd1f998009e97470a65fba8a499a0d9Lubos Kosco &lt;VirtualHost www.baygroup.org&gt;
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan ServerAdmin webmaster@mail.baygroup.org
305373bfa854723d80c740a2ff9d277d0f34082aHarry Pan DocumentRoot /groups/baygroup/www
ServerName www.baygroup.org
ErrorLog /groups/baygroup/logs/error_log
TransferLog /groups/baygroup/logs/access_log
&lt;/VirtualHost&gt;
</pre>
It is recommended that you use an IP address instead of a hostname
(see <A HREF="/dns-caveats.html">DNS page</A>).
<P>
Almost <strong>any</strong> configuration directive can be put
in the VirtualHost directive, with the exception of
<A HREF="/mod/core.html#servertype">ServerType</A>,
<A HREF="/mod/core.html#startservers">StartServers</A>,
<A HREF="/mod/core.html#maxspareservers">MaxSpareServers</A>,
<A HREF="/mod/core.html#minspareservers">MinSpareServers</A>,
<A HREF="/mod/core.html#maxrequestsperchild">MaxRequestsPerChild</A>,
<A HREF="/mod/core.html#bindaddress">BindAddress</A>,
<A HREF="/mod/core.html#listen">Listen</A>,
<A HREF="/mod/core.html#pidfile">PidFile</A>,
<A HREF="/mod/mod_mime.html#typesconfig">TypesConfig</A>,
<A HREF="/mod/core.html#serverroot">ServerRoot</A> and
<A HREF="/mod/core.html#namevirtualhost">NameVirtualHost</A>.
<P>
<A HREF="/mod/core.html#user">User</A> and
<A HREF="/mod/core.html#group">Group</A> maybe used inside a VirtualHost
directive if the <A HREF="/suexec.html">suEXEC wrapper</A> is used.
<P>
<EM>SECURITY:</EM> When specifying where to write log files, be aware
of some security risks which are present if anyone other than the
user that starts Apache has write access to the directory where they
are written. See the <A HREF="/misc/security_tips.html">security
tips</A> document for details.
</P>
<!--#include virtual="footer.html" -->
</body>
</html>