mass.xml revision ffec3e56ff5331a2d732ec07e9d107303fed43f4
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<?xml version='1.0' encoding='UTF-8' ?>
530eba85dbd41b8a0fa5255d3648d1440199a661slive<!DOCTYPE manualpage SYSTEM "/style/manualpage.dtd">
e942c741056732f50da2074b36fe59805d370650slive<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<!-- $LastChangedRevision$ -->
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<!--
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive Licensed to the Apache Software Foundation (ASF) under one or more
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive contributor license agreements. See the NOTICE file distributed with
530eba85dbd41b8a0fa5255d3648d1440199a661slive this work for additional information regarding copyright ownership.
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive The ASF licenses this file to You under the Apache License, Version 2.0
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive (the "License"); you may not use this file except in compliance with
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive the License. You may obtain a copy of the License at
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive http://www.apache.org/licenses/LICENSE-2.0
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive Unless required by applicable law or agreed to in writing, software
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive distributed under the License is distributed on an "AS IS" BASIS,
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive See the License for the specific language governing permissions and
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive limitations under the License.
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive-->
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<manualpage metafile="mass.xml.meta">
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<parentdocument href="./">Virtual Hosts</parentdocument>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <title>Dynamically Configured Mass Virtual Hosting</title>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<summary>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>This document describes how to efficiently serve an
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive arbitrary number of virtual hosts with the Apache HTTP Server. A
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <a href="/rewrite/mass.html">separate document</a> discusses using
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <module>mod_rewrite</module> to create dynamic mass virtual hosts.
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive </p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</summary>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<section id="motivation"><title>Motivation</title>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>The techniques described here are of interest if your
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <code>httpd.conf</code> contains many
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <code>&lt;VirtualHost&gt;</code> sections that are
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive substantially the same, for example:</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<example>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<pre>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;VirtualHost 111.22.33.44&gt;
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive ServerName customer-1.example.com
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive DocumentRoot /www/hosts/customer-1.example.com/docs
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive ScriptAlias /cgi-bin/ /www/hosts/customer-1.example.com/cgi-bin
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;/VirtualHost&gt;
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;VirtualHost 111.22.33.44&gt;
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive ServerName customer-2.example.com
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive DocumentRoot /www/hosts/customer-2.example.com/docs
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive ScriptAlias /cgi-bin/ /www/hosts/customer-2.example.com/cgi-bin
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;/VirtualHost&gt;
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;VirtualHost 111.22.33.44&gt;
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive ServerName customer-N.example.com
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive DocumentRoot /www/hosts/customer-N.example.com/docs
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive ScriptAlias /cgi-bin/ /www/hosts/customer-N.example.com/cgi-bin
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;/VirtualHost&gt;
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</pre>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</example>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>We wish to replace these multiple
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <code>&lt;VirtualHost&gt;</code> blocks with a mechanism
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive that works them out dynamically. This has a number of
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive advantages:</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <ol>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <li>Your configuration file is smaller, so Apache starts
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive more quickly and uses less memory. Perhaps more importantly, the
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive smaller configuration is easier to maintain, and leaves less room
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive for errors.</li>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <li>Adding virtual hosts is simply a matter of creating the
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive appropriate directories in the filesystem and entries in the
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive DNS - you don't need to reconfigure or restart Apache.</li>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive </ol>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>The main disadvantage is that you cannot have a different log file for
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive each virtual host; however, if you have many virtual hosts, doing
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive this can be a bad idea anyway, because of the <a
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive href="fd-limits.html">number of file descriptors needed</a>.
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive It is better to <a href="/logs.html#piped">log to a pipe or a fifo</a>,
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive and arrange for the process at the other end to split up the log
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive files into one per virtual host. One example of such a process can
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive be found in the <a
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive href="/programs/other.html#split-logfile">split-logfile</a>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive utility.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</section>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<section id="overview"><title>Overview</title>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>A virtual host is defined by two pieces of information: its
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive IP address, and the contents of the <code>Host:</code> header
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive in the HTTP request. The dynamic mass virtual hosting technique
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive used here is based on automatically inserting this information into the
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive pathname of the file that is used to satisfy the request. This
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive can be most easily done by using <module>mod_vhost_alias</module>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive with Apache httpd. Alternatively,
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <a href="/rewrite/vhosts.html">mod_rewrite can
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive be used</a>.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>Both of these modules are disabled by default; you must enable
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive one of them when configuring and building Apache httpd if you want to
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive use this technique.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>A couple of things need to be determined from the request in
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive order to make the dynamic
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive virtual host look like a normal one. The most important is the
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive server name, which is used by the server to generate
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive self-referential URLs etc. It is configured with the
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <code>ServerName</code> directive, and it is available to CGIs
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive via the <code>SERVER_NAME</code> environment variable. The
530eba85dbd41b8a0fa5255d3648d1440199a661slive actual value used at run time is controlled by the <directive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive module="core">UseCanonicalName</directive>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive setting. With <code>UseCanonicalName Off</code>, the server name
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive is taken from the contents of the <code>Host:</code> header in the
530eba85dbd41b8a0fa5255d3648d1440199a661slive request. With <code>UseCanonicalName DNS</code>, it is taken from a
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive reverse DNS lookup of the virtual host's IP address. The former
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive setting is used for name-based dynamic virtual hosting, and the
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive latter is used for IP-based hosting. If httpd cannot work out
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive the server name because there is no <code>Host:</code> header,
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive or the DNS lookup fails, then the value configured with
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <code>ServerName</code> is used instead.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>The other thing to determine is the document root (configured
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive with <code>DocumentRoot</code> and available to CGI scripts via the
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <code>DOCUMENT_ROOT</code> environment variable). In a normal
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive configuration, this is used by the core module when
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive mapping URIs to filenames, but when the server is configured to
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive do dynamic virtual hosting, that job must be taken over by another
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive module (either <module>mod_vhost_alias</module> or
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <module>mod_rewrite</module>), which has a different way of doing
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive the mapping. Neither of these modules is responsible for
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive setting the <code>DOCUMENT_ROOT</code> environment variable so
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive if any CGIs or SSI documents make use of it, they will get a
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive misleading value.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</section>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<section id="simple"><title>Dynamic Virtual Hosts with
80c4526970a11f37c0f8e3b82afdf03902dac3f3slivemod_vhost_alias</title>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>This extract from <code>httpd.conf</code> implements the
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive virtual host arrangement outlined in the <a
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive href="#motivation">Motivation</a> section above
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive using <module>mod_vhost_alias</module>.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<example>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive# get the server name from the Host: header<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveUseCanonicalName Off<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive# this log format can be split per-virtual-host based on the first field<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive# using the split-logfile utility.<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveLogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveCustomLog logs/access_log vcommon<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive# include the server name in the filenames used to satisfy requests<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveVirtualDocumentRoot /www/hosts/%0/docs<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveVirtualScriptAlias /www/hosts/%0/cgi-bin
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</example>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>This configuration can be changed into an IP-based virtual
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive hosting solution by just turning <code>UseCanonicalName
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive Off</code> into <code>UseCanonicalName DNS</code>. The server
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive name that is inserted into the filename is then derived from
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive the IP address of the virtual host. The variable <code>%0</code>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive references the requested servername, as indicated in the
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <code>Host:</code> header.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<p>See the <module>mod_vhost_alias</module> documentation for more usage
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveexamples.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</section>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<section id="homepages"><title>Simplified Dynamic Virtual Hosts</title>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>This is an adjustment of the above system, tailored for an
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive ISP's web hosting server. Using <code>%2</code>,
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive we can select substrings of the server name to
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive use in the filename so that, for example, the documents for
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <code>www.user.example.com</code> are found in
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <code>/home/user/www</code>. It uses a single <code>cgi-bin</code>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive directory instead of one per virtual host.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<example>
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveUseCanonicalName Off<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveLogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveCustomLog logs/access_log vcommon<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive# include part of the server name in the filenames<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveVirtualDocumentRoot /home/%2/www<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive# single cgi-bin directory<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveScriptAlias /cgi-bin/ /www/std-cgi/<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</example>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>There are examples of more complicated
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <code>VirtualDocumentRoot</code> settings in the
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <module>mod_vhost_alias</module> documentation.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</section>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<section id="combinations"><title>Using Multiple Virtual
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive Hosting Systems on the Same Server</title>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>With more complicated setups, you can use httpd's normal
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <code>&lt;VirtualHost&gt;</code> directives to control the
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive scope of the various virtual hosting configurations. For
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive example, you could have one IP address for general customers' homepages,
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive and another for commercial customers, with the following setup.
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive This can be combined with conventional
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <code>&lt;VirtualHost&gt;</code> configuration sections, as shown
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive below.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<example>
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveUseCanonicalName Off<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveLogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;Directory /www/commercial&gt;<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<indent>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive Options FollowSymLinks<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive AllowOverride All<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</indent>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;/Directory&gt;<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;Directory /www/homepages&gt;<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<indent>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive Options FollowSymLinks<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive AllowOverride None<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</indent>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;/Directory&gt;<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;VirtualHost 111.22.33.44&gt;<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<indent>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive ServerName www.commercial.example.com<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive CustomLog logs/access_log.commercial vcommon<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive VirtualDocumentRoot /www/commercial/%0/docs<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive VirtualScriptAlias /www/commercial/%0/cgi-bin<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</indent>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;/VirtualHost&gt;<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;VirtualHost 111.22.33.45&gt;<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<indent>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive ServerName www.homepages.example.com<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive CustomLog logs/access_log.homepages vcommon<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive VirtualDocumentRoot /www/homepages/%0/docs<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive ScriptAlias /cgi-bin/ /www/std-cgi/<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</indent>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive&lt;/VirtualHost&gt;
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</example>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<note>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <title>Note</title>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>If the first VirtualHost block does <em>not</em> include a
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <directive module="core">ServerName</directive> directive, the reverse
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive DNS of the relevant IP will be used instead.
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive If this is not the server name you
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive wish to use, a bogus entry (eg. <code>ServerName
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive none.example.com</code>) can be added to get around this
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive behaviour.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</note>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</section>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<section id="ipbased"><title>More Efficient IP-Based Virtual Hosting</title>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive <p>The configuration changes suggested to turn <a href="#simple">the first
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive example</a> into an IP-based virtual hosting setup result in
530eba85dbd41b8a0fa5255d3648d1440199a661slive a rather inefficient setup. A new DNS lookup is required for every
530eba85dbd41b8a0fa5255d3648d1440199a661slive request. To avoid this overhead, the filesystem can be arranged to
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive correspond to the IP addresses, instead of to the host names, thereby
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive negating the need for a DNS lookup. Logging will also have to be adjusted
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive to fit this system.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<example>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive# get the server name from the reverse DNS of the IP address<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveUseCanonicalName DNS<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive# include the IP address in the logs so they may be split<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveLogFormat "%A %h %l %u %t \"%r\" %s %b" vcommon<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveCustomLog logs/access_log vcommon<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive# include the IP address in the filenames<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveVirtualDocumentRootIP /www/hosts/%0/docs<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveVirtualScriptAliasIP /www/hosts/%0/cgi-bin<br />
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</example>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</section>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<section id="rewrite"><title>Mass virtual hosts with
80c4526970a11f37c0f8e3b82afdf03902dac3f3slivemod_rewrite</title>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveMass virtual hosting may also be accomplished using
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive<module>mod_rewrite</module>, either using simple <directive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slivemodule="mod_rewrite">RewriteRule</directive> directives, or using more
80c4526970a11f37c0f8e3b82afdf03902dac3f3slivecomplicated techniques such as storing the vhost definitions externally
80c4526970a11f37c0f8e3b82afdf03902dac3f3sliveand accessing them via <directive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slivemodule="mod_rewrite">RewriteMap</directive>. These techniques are
80c4526970a11f37c0f8e3b82afdf03902dac3f3slivediscussed in the <a href="/rewrite/vhosts.html">rewrite
80c4526970a11f37c0f8e3b82afdf03902dac3f3slivedocumentation</a>.</p>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</section>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive</manualpage>
80c4526970a11f37c0f8e3b82afdf03902dac3f3slive