details.html.en revision 60a4b2c422dcbb08a554fb193105c08da592718b
181e56d8b348d301d615ccf5465ae600fee2867berikabele<?xml version="1.0" encoding="ISO-8859-1"?>
181e56d8b348d301d615ccf5465ae600fee2867berikabele<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
181e56d8b348d301d615ccf5465ae600fee2867berikabele<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele This file is generated from xml source: DO NOT EDIT
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5a58787efeb02a1c3f06569d019ad81fd2efa06end -->
5a58787efeb02a1c3f06569d019ad81fd2efa06end<title>An In-Depth Discussion of Virtual Host Matching - Apache HTTP Server</title>
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<link href="/images/favicon.ico" rel="shortcut icon" /></head>
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<body id="manual-page"><div id="page-header">
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim<p class="apache">Apache HTTP Server Version 2.3</p>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<img alt="" src="/images/feather.gif" /></div>
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<div id="path">
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.3</a> &gt; <a href="./">Virtual Hosts</a></div><div id="page-content"><div id="preamble"><h1>An In-Depth Discussion of Virtual Host Matching</h1>
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim<div class="toplang">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<p><span>Available Languages: </span><a href="/en/vhosts/details.html" title="English">&nbsp;en&nbsp;</a> |
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<a href="/fr/vhosts/details.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd<a href="/ko/vhosts/details.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim<a href="/tr/vhosts/details.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
af84459fbf938e508fd10b01cb8d699c79083813takashi</div>
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0nd
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung <p>This document attempts to explain
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd exactly what Apache HTTP Server does when deciding what virtual host to
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd serve a request from.</p>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim <p>Most users should read about <a href="name-based.html#namevip">
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele Name-based vs. IP-based Virtual Hosts</a> to decide which type they
5a58787efeb02a1c3f06569d019ad81fd2efa06end want to use, then read more about <a href="name-based.html">name-based</a>
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim or <a href="ip-based.html">IP-based</a> virtualhosts, and then see
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim <a href="examples.html">some examples</a>.</p>
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim
709e3a21ba73b8433462959cd56c773454b34441trawick <p>If you want to understand all the details, then you can
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh come back to this page.</p>
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim
5a58787efeb02a1c3f06569d019ad81fd2efa06end</div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#configparsing">Configuration File</a></li>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele<li><img alt="" src="/images/down.gif" /> <a href="#hostmatching">Virtual Host Matching</a></li>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele<li><img alt="" src="/images/down.gif" /> <a href="#tips">Tips</a></li>
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim</ul><h3>See also</h3><ul class="seealso"><li><a href="ip-based.html">IP-based Virtual Host Support</a></li><li><a href="name-based.html">Name-based Virtual Hosts Support</a></li><li><a href="examples.html">Virtual Host examples for common setups</a></li><li><a href="mass.html">Dynamically configured mass virtual hosting</a></li></ul></div>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim<div class="section">
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim<h2><a name="configparsing" id="configparsing">Configuration File</a></h2>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele <p>There is a <em>main server</em> which consists of all the
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim definitions appearing outside of
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele <code>&lt;VirtualHost&gt;</code> sections.</p>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim <p>There are virtual
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim servers, called <em>vhosts</em>, which are defined by
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim <code class="directive"><a href="/mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele sections.</p>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele <p>Each <code>VirtualHost</code> directive includes one
dfc515decf0e3a5a980ec4e06af4eb76d4a95440rbowen or more addresses and optional ports.</p>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele <p>Hostnames can be used in place of IP addresses in a virtual
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim host definition, but they are resolved at startup and if any name
5a58787efeb02a1c3f06569d019ad81fd2efa06end resolutions fail, those virtual host definitions are ignored.
5a58787efeb02a1c3f06569d019ad81fd2efa06end This is, therefore, not recommended.</p>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele <p>If using IP-based vhosts, the address can be specified
709e3a21ba73b8433462959cd56c773454b34441trawick as <code>_default_</code>, which will match a request if no
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen other vhost has the explicit address on which the request was
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen received.</p>
dfc515decf0e3a5a980ec4e06af4eb76d4a95440rbowen
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele <p>If using name-based vhosts, the address can be specified as
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim <code>*</code>, which will match a request if no
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele other vhost has the explicit address on which the request was
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele received. The corresponding <code>NameVirtualHost</code>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele directive must also use <code>*</code>.</p>
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim
5a58787efeb02a1c3f06569d019ad81fd2efa06end <p>The address appearing in the <code>VirtualHost</code>
5a58787efeb02a1c3f06569d019ad81fd2efa06end directive can have an optional port. If the port is unspecified,
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele it is treated as a wildcard port, which can also be indicated
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele explicitly using <code>*</code>.
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim The wildcard port matches any port.</p>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele <p>(Port numbers specified in the <code>VirtualHost</code> directive do
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele not influence what port numbers Apache will listen on, they only control
dfc515decf0e3a5a980ec4e06af4eb76d4a95440rbowen which <code>VirtualHost</code> will be selected to handle a request.
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele Use the <code class="directive"><a href="/mod/core.html#listen">Listen</a></code> directive to
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele control the addresses and ports on which the server listens.)
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele </p>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele <p>Collectively the
dfc515decf0e3a5a980ec4e06af4eb76d4a95440rbowen entire set of addresses (including multiple
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele results from DNS lookups) are called the vhost's
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele <em>address set</em>.</p>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim <p>If you want Apache to discriminate on the
87ffb6e33f3cbef3b9bb406cc2d27039fa336eaatrawick basis of the HTTP <code>Host</code> header supplied by the client,
709e3a21ba73b8433462959cd56c773454b34441trawick the <code>NameVirtualHost</code> directive <em>must</em> appear
709e3a21ba73b8433462959cd56c773454b34441trawick with the exact IP address (or wildcard) and port pair used in a
709e3a21ba73b8433462959cd56c773454b34441trawick corresponding set of <code>VirtualHost</code> directives.</p>
709e3a21ba73b8433462959cd56c773454b34441trawick
709e3a21ba73b8433462959cd56c773454b34441trawick <p>The
709e3a21ba73b8433462959cd56c773454b34441trawick <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> directive
709e3a21ba73b8433462959cd56c773454b34441trawick may appear anywhere within the definition of a server. However,
709e3a21ba73b8433462959cd56c773454b34441trawick each appearance overrides the previous appearance (within that
709e3a21ba73b8433462959cd56c773454b34441trawick server). If no <code>ServerName</code> is specified, the server
709e3a21ba73b8433462959cd56c773454b34441trawick attempts to deduce it from the server's IP address.</p>
709e3a21ba73b8433462959cd56c773454b34441trawick
5a58787efeb02a1c3f06569d019ad81fd2efa06end <p>Multiple <code>NameVirtualHost</code> directives can be used,
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd each with a set of <code>VirtualHost</code> directives, but only
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim one <code>NameVirtualHost</code> directive should be used for
af84459fbf938e508fd10b01cb8d699c79083813takashi each specific IP:port pair.</p>
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0nd
f3ec420152ca921e4c1ce77782f51b53f659018dnd <p>The first name-based vhost in the configuration file for a
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung given IP:port pair is significant because it is used for all
727872d18412fc021f03969b8641810d8896820bhumbedooh requests received on that address and port for which no other
0d0ba3a410038e179b695446bb149cce6264e0abnd vhost for that IP:port pair has a matching ServerName or
727872d18412fc021f03969b8641810d8896820bhumbedooh ServerAlias. It is also used for all SSL connections if the
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh server does not support <a class="glossarylink" href="/glossary.html#servernameindication" title="see glossary">Server Name Indication</a>.</p>
0d0ba3a410038e179b695446bb149cce6264e0abnd
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh <p>If there are no vhosts defined for an address in a
727872d18412fc021f03969b8641810d8896820bhumbedooh <code>NameVirtualHost</code> directive, the
0d0ba3a410038e179b695446bb149cce6264e0abnd <code>NameVirtualHost</code> directive is ignored at startup and an error is
0d0ba3a410038e179b695446bb149cce6264e0abnd logged.</p>
0d0ba3a410038e179b695446bb149cce6264e0abnd
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh <p>The ordering of <code>NameVirtualHost</code> and
0d0ba3a410038e179b695446bb149cce6264e0abnd <code>VirtualHost</code> directives is not important, which
0d0ba3a410038e179b695446bb149cce6264e0abnd makes the following two examples identical (only the order of
0d0ba3a410038e179b695446bb149cce6264e0abnd the <code>VirtualHost</code> directives for <em>one</em>
727872d18412fc021f03969b8641810d8896820bhumbedooh address set is important, see below):</p>
0d0ba3a410038e179b695446bb149cce6264e0abnd
0d0ba3a410038e179b695446bb149cce6264e0abnd<table><tr>
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh<td><div class="example"><p><code>
5effc8b39fae5cd169d17f342bfc265705840014rbowen NameVirtualHost 111.22.33.44<br />
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen &lt;VirtualHost 111.22.33.44&gt;<br />
0d0ba3a410038e179b695446bb149cce6264e0abnd # server A<br />
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd ...<br />
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd &lt;/VirtualHost&gt;<br />
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd &lt;VirtualHost 111.22.33.44&gt;<br />
5a58787efeb02a1c3f06569d019ad81fd2efa06end # server B<br />
...<br />
&lt;/VirtualHost&gt;<br />
<br />
NameVirtualHost 111.22.33.55<br />
&lt;VirtualHost 111.22.33.55&gt;<br />
# server C<br />
...<br />
&lt;/VirtualHost&gt;<br />
&lt;VirtualHost 111.22.33.55&gt;<br />
# server D<br />
...<br />
&lt;/VirtualHost&gt;
</code></p></div></td>
<td><div class="example"><p><code>
&lt;VirtualHost 111.22.33.44&gt;<br />
# server A<br />
&lt;/VirtualHost&gt;<br />
&lt;VirtualHost 111.22.33.55&gt;<br />
# server C<br />
...<br />
&lt;/VirtualHost&gt;<br />
&lt;VirtualHost 111.22.33.44&gt;<br />
# server B<br />
...<br />
&lt;/VirtualHost&gt;<br />
&lt;VirtualHost 111.22.33.55&gt;<br />
# server D<br />
...<br />
&lt;/VirtualHost&gt;<br />
<br />
NameVirtualHost 111.22.33.44<br />
NameVirtualHost 111.22.33.55<br />
<br />
</code></p></div></td>
</tr></table>
<p>(To aid the readability of your configuration you should
prefer the left variant.)</p>
<p>For every vhost various default values are set. In
particular:</p>
<ol>
<li>If a vhost has no <code class="directive"><a href="/mod/core.html#serveradmin">ServerAdmin</a></code>,
<code class="directive"><a href="/mod/core.html#resourceconfig">ResourceConfig</a></code>,
<code class="directive"><a href="/mod/core.html#accessconfig">AccessConfig</a></code>,
<code class="directive"><a href="/mod/core.html#timeout">Timeout</a></code>,
<code class="directive"><a href="/mod/core.html#keepalivetimeout">KeepAliveTimeout</a></code>,
<code class="directive"><a href="/mod/core.html#keepalive">KeepAlive</a></code>,
<code class="directive"><a href="/mod/core.html#maxkeepaliverequests">MaxKeepAliveRequests</a></code>,
<code class="directive"><a href="/mod/core.html#receivebuffersize">ReceiveBufferSize</a></code>,
or <code class="directive"><a href="/mod/core.html#sendbuffersize">SendBufferSize</a></code>
directive then the respective value is inherited from the
main server. (That is, inherited from whatever the final
setting of that value is in the main server.)</li>
<li>The "lookup defaults" that define the default directory
permissions for a vhost are merged with those of the
main server. This includes any per-directory configuration
information for any module.</li>
<li>The per-server configs for each module from the
main server are merged into the vhost server.</li>
</ol>
<p>Essentially, the main server is treated as "defaults" or a
"base" on which to build each vhost. But the positioning of
these main server definitions in the config file is largely
irrelevant -- the entire config of the main server has been
parsed when this final merging occurs. So even if a main server
definition appears after a vhost definition it might affect the
vhost definition.</p>
<p>If the main server has no <code>ServerName</code> at this
point, then the hostname of the machine that <code class="program"><a href="/programs/httpd.html">httpd</a></code>
is running on is used instead. We will call the <em>main server address
set</em> those IP addresses returned by a DNS lookup on the
<code>ServerName</code> of the main server.</p>
<p>For any undefined <code>ServerName</code> fields, a
name-based vhost defaults to the address given first in the
<code>VirtualHost</code> statement defining the vhost.</p>
<p>Any vhost that includes the magic <code>_default_</code>
wildcard is given the same <code>ServerName</code> as the
main server.</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="section">
<h2><a name="hostmatching" id="hostmatching">Virtual Host Matching</a></h2>
<p>The server determines which vhost to use for a request as
follows:</p>
<h3><a name="hashtable" id="hashtable">IP address lookup</a></h3>
<p>When the connection is first received on some address and port,
the server looks for all the <code>VirtualHost</code> definitions
that have the same IP address and port.</p>
<p>If there are no exact matches for the address and port, then
wildcard (<code>*</code>) matches are considered.</p>
<p>If there are still no matches, then vhosts with IP
address specified as <code>_default_</code> that match the
port are considered.</p>
<p>If no matches are found, the request is served by the
main server.</p>
<p>If there are <code>VirtualHost</code> definitions for
the IP address, the next step is to decide if we have to
deal with an IP-based or a name-based vhost.</p>
<h3><a name="ipbased" id="ipbased">IP-based vhost</a></h3>
<p>If there is no <code>NameVirtualHost</code> directive
matching the vhost, no further actions are performed and
the request is served from the first matching vhost.</p>
<h3><a name="namebased" id="namebased">Name-based vhost</a></h3>
<p>If the entry corresponds to a name-based vhost, the "list" in
the remaining steps refers to the list of vhosts that matched, in
the order they were in the configuration file.</p>
<p>If the connection is using SSL, the server supports <a class="glossarylink" href="/glossary.html#servernameindication" title="see glossary">Server Name Indication</a>, and
the SSL client handshake includes the TLS extension with the
requested hostname, then that hostname is used below just like the
<code>Host:</code> header would be used on a non-SSL connection.
Otherwise, the first name-based vhost whose address matched is
used for SSL connections. This is significant because the
vhost determines which certificate the server will use for the
connection.</p>
<p>If the request contains a <code>Host:</code> header field, the
list is searched for the first vhost with a matching
<code>ServerName</code> or <code>ServerAlias</code>, and the
request is served from that vhost. A <code>Host:</code> header
field can contain a port number, but Apache always ignores it and
matches against the real port to which the client sent the
request.</p>
<p>The first vhost in the config
file with the specified IP address has the highest priority
and catches any request to an unknown server name, or a request
without a <code>Host:</code> header field (such as a HTTP/1.0
request).</p>
<h3><a name="persistent" id="persistent">Persistent connections</a></h3>
<p>The <em>IP lookup</em> described above is only done <em>once</em> for a
particular TCP/IP session while the <em>name lookup</em> is done on
<em>every</em> request during a KeepAlive/persistent
connection. In other words, a client may request pages from
different name-based vhosts during a single persistent
connection.</p>
<h3><a name="absoluteURI" id="absoluteURI">Absolute URI</a></h3>
<p>If the URI from the request is an absolute URI, and its
hostname and port match the main server or one of the
configured virtual hosts <em>and</em> match the address and
port to which the client sent the request, then the
scheme/hostname/port prefix is stripped off and the remaining
relative URI is served by the corresponding main server or
virtual host. If it does not match, then the URI remains
untouched and the request is taken to be a proxy request.</p>
<h3><a name="observations" id="observations">Observations</a></h3>
<ul>
<li>A name-based vhost can never interfere with an IP-base
vhost and vice versa. IP-based vhosts can only be reached
through an IP address of its own address set and never
through any other address. The same applies to name-based
vhosts, they can only be reached through an IP address of the
corresponding address set which must be defined with a
<code>NameVirtualHost</code> directive.</li>
<li><code>ServerAlias</code>
checks are never performed for an IP-based vhost.</li>
<li>The order of name-/IP-based, the <code>_default_</code>
vhost and the <code>NameVirtualHost</code> directive within
the config file is not important. Only the ordering of
name-based vhosts for a specific address set is significant.
The one name-based vhosts that comes first in the
configuration file has the highest priority for its
corresponding address set.</li>
<li>Any port in the <code>Host:</code> header field is never used during the
matching process. Apache always uses the real port to which
the client sent the request.</li>
<li>If two IP-based vhosts have an address in common, the
vhost appearing first in the config file is always matched.
Such a thing might happen inadvertently. The server will give
a warning in the error logfile when it detects this.</li>
<li>A <code>_default_</code> vhost catches a request only if
there is no other vhost with a matching IP address
<em>and</em> a matching port number for the request. The
request is only caught if the port number to which the client
sent the request matches the port number of your
<code>_default_</code> vhost which is your standard
<code>Listen</code> by default. A wildcard port can be
specified (<em>i.e.</em>, <code>_default_:*</code>) to catch
requests to any available port. This also applies to
<code>NameVirtualHost *</code> vhosts. Note that this is simply an
extension of the "best match" principle, as a specific and exact match
is favored over a wildcard.</li>
<li>The main server is only used to serve a request if the IP
address and port number to which the client connected
does not match any vhost (including a
<code>_default_</code> vhost). In other words, the main server
only catches a request for an unspecified address/port
combination (unless there is a <code>_default_</code> vhost
which matches that port).</li>
<li>A <code>_default_</code> vhost or the main server is
<em>never</em> matched for a request with an unknown or
missing <code>Host:</code> header field if the client
connected to an address (and port) which is used for
name-based vhosts, <em>e.g.</em>, in a
<code>NameVirtualHost</code> directive.</li>
<li>You should never specify DNS names in
<code>VirtualHost</code> directives because it will force
your server to rely on DNS to boot. Furthermore it poses a
security threat if you do not control the DNS for all the
domains listed. There's <a href="/dns-caveats.html">more
information</a> available on this and the next two
topics.</li>
<li><code>ServerName</code> should always be set for each
vhost. Otherwise A DNS lookup is required for each
vhost.</li>
</ul>
</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="section">
<h2><a name="tips" id="tips">Tips</a></h2>
<p>In addition to the tips on the <a href="/dns-caveats.html#tips">DNS Issues</a> page, here are
some further tips:</p>
<ul>
<li>Place all main server definitions before any
<code>VirtualHost</code> definitions. (This is to aid the
readability of the configuration -- the post-config merging
process makes it non-obvious that definitions mixed in around
virtual hosts might affect all virtual hosts.)</li>
<li>Group corresponding <code>NameVirtualHost</code> and
<code>VirtualHost</code> definitions in your configuration to
ensure better readability.</li>
</ul>
</div></div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="/en/vhosts/details.html" title="English">&nbsp;en&nbsp;</a> |
<a href="/fr/vhosts/details.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
<a href="/ko/vhosts/details.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
<a href="/tr/vhosts/details.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
</div><div id="footer">
<p class="apache">Copyright 2010 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div>
</body></html>