details.html.en revision 9c1260efa52c82c2a58e5b5f20cd6902563d95f5
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<?xml version="1.0" encoding="ISO-8859-1"?>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess This file is generated from xml source: DO NOT EDIT
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5a58787efeb02a1c3f06569d019ad81fd2efa06end -->
5a58787efeb02a1c3f06569d019ad81fd2efa06end<title>An In-Depth Discussion of Virtual Host Matching - Apache HTTP Server</title>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
5a58787efeb02a1c3f06569d019ad81fd2efa06end<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
5a58787efeb02a1c3f06569d019ad81fd2efa06end<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
5a58787efeb02a1c3f06569d019ad81fd2efa06end<link href="/images/favicon.ico" rel="shortcut icon" /></head>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<body id="manual-page"><div id="page-header">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<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>
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz<p class="apache">Apache HTTP Server Version 2.3</p>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<img alt="" src="/images/feather.gif" /></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div id="path">
4b5981e276e93df97c34e4da05ca5cf8bbd937dand<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>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd<div class="toplang">
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/vhosts/details.html" title="English">&nbsp;en&nbsp;</a> |
d05d0eb4ae6d2a5e513fc3bf2555ce33da416634nd<a href="/fr/vhosts/details.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
4b3a8afbfcea8b265d179a122bf40dfedd1ce280takashi<a href="/ko/vhosts/details.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
4b3a8afbfcea8b265d179a122bf40dfedd1ce280takashi<a href="/tr/vhosts/details.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd</div>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
15107611640cec4e666dd7e2e1dee15c270e9e98rbowen <p>This document attempts to explain
15107611640cec4e666dd7e2e1dee15c270e9e98rbowen exactly what Apache HTTP Server does when deciding what virtual host to
15107611640cec4e666dd7e2e1dee15c270e9e98rbowen serve a request from.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>Most users should read about <a href="name-based.html#namevip">
60a4b2c422dcbb08a554fb193105c08da592718bpoirier Name-based vs. IP-based Virtual Hosts</a> to decide which type they
60a4b2c422dcbb08a554fb193105c08da592718bpoirier want to use, then read more about <a href="name-based.html">name-based</a>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier or <a href="ip-based.html">IP-based</a> virtualhosts, and then see
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <a href="examples.html">some examples</a>.</p>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>If you want to understand all the details, then you can
60a4b2c422dcbb08a554fb193105c08da592718bpoirier come back to this page.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5a58787efeb02a1c3f06569d019ad81fd2efa06end</div>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#configparsing">Configuration File</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#hostmatching">Virtual Host Matching</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#tips">Tips</a></li>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier</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>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
60a4b2c422dcbb08a554fb193105c08da592718bpoirier<h2><a name="configparsing" id="configparsing">Configuration File</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>There is a <em>main server</em> which consists of all the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess definitions appearing outside of
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <code>&lt;VirtualHost&gt;</code> sections.</p>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>There are virtual
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess servers, called <em>vhosts</em>, which are defined by
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code class="directive"><a href="/mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess sections.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>Each <code>VirtualHost</code> directive includes one
60a4b2c422dcbb08a554fb193105c08da592718bpoirier or more addresses and optional ports.</p>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>Hostnames can be used in place of IP addresses in a virtual
60a4b2c422dcbb08a554fb193105c08da592718bpoirier host definition, but they are resolved at startup and if any name
60a4b2c422dcbb08a554fb193105c08da592718bpoirier resolutions fail, those virtual host definitions are ignored.
60a4b2c422dcbb08a554fb193105c08da592718bpoirier This is, therefore, not recommended.</p>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf <p>The address can be specified as
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <code>*</code>, which will match a request if no
60a4b2c422dcbb08a554fb193105c08da592718bpoirier other vhost has the explicit address on which the request was
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf received. </p>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>The address appearing in the <code>VirtualHost</code>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier directive can have an optional port. If the port is unspecified,
60a4b2c422dcbb08a554fb193105c08da592718bpoirier it is treated as a wildcard port, which can also be indicated
60a4b2c422dcbb08a554fb193105c08da592718bpoirier explicitly using <code>*</code>.
60a4b2c422dcbb08a554fb193105c08da592718bpoirier The wildcard port matches any port.</p>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>(Port numbers specified in the <code>VirtualHost</code> directive do
60a4b2c422dcbb08a554fb193105c08da592718bpoirier not influence what port numbers Apache will listen on, they only control
60a4b2c422dcbb08a554fb193105c08da592718bpoirier which <code>VirtualHost</code> will be selected to handle a request.
60a4b2c422dcbb08a554fb193105c08da592718bpoirier Use the <code class="directive"><a href="/mod/core.html#listen">Listen</a></code> directive to
60a4b2c422dcbb08a554fb193105c08da592718bpoirier control the addresses and ports on which the server listens.)
60a4b2c422dcbb08a554fb193105c08da592718bpoirier </p>
1696993fbee984b093ae8b823e3ea3fa80eae486covener
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>Collectively the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier entire set of addresses (including multiple
60a4b2c422dcbb08a554fb193105c08da592718bpoirier results from DNS lookups) are called the vhost's
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>address set</em>.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf <p>Apache automatically discriminates on the
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf basis of the HTTP <code>Host</code> header supplied by the client
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf whenever the most specific match for an IP address and port combination
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf is listed in multiple virtual hosts.</p>
1696993fbee984b093ae8b823e3ea3fa80eae486covener
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>The
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> directive
60a4b2c422dcbb08a554fb193105c08da592718bpoirier may appear anywhere within the definition of a server. However,
60a4b2c422dcbb08a554fb193105c08da592718bpoirier each appearance overrides the previous appearance (within that
60a4b2c422dcbb08a554fb193105c08da592718bpoirier server). If no <code>ServerName</code> is specified, the server
60a4b2c422dcbb08a554fb193105c08da592718bpoirier attempts to deduce it from the server's IP address.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>The first name-based vhost in the configuration file for a
60a4b2c422dcbb08a554fb193105c08da592718bpoirier given IP:port pair is significant because it is used for all
60a4b2c422dcbb08a554fb193105c08da592718bpoirier requests received on that address and port for which no other
60a4b2c422dcbb08a554fb193105c08da592718bpoirier vhost for that IP:port pair has a matching ServerName or
60a4b2c422dcbb08a554fb193105c08da592718bpoirier ServerAlias. It is also used for all SSL connections if the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier server does not support <a class="glossarylink" href="/glossary.html#servernameindication" title="see glossary">Server Name Indication</a>.</p>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>For every vhost various default values are set. In
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess particular:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <ol>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>If a vhost has no <code class="directive"><a href="/mod/core.html#serveradmin">ServerAdmin</a></code>,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code class="directive"><a href="/mod/core.html#resourceconfig">ResourceConfig</a></code>,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code class="directive"><a href="/mod/core.html#accessconfig">AccessConfig</a></code>,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code class="directive"><a href="/mod/core.html#timeout">Timeout</a></code>,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code class="directive"><a href="/mod/core.html#keepalivetimeout">KeepAliveTimeout</a></code>,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code class="directive"><a href="/mod/core.html#keepalive">KeepAlive</a></code>,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code class="directive"><a href="/mod/core.html#maxkeepaliverequests">MaxKeepAliveRequests</a></code>,
2bc7f1cf720973a67f8ff7a8d523e40569ae5b6cnd <code class="directive"><a href="/mod/core.html#receivebuffersize">ReceiveBufferSize</a></code>,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess or <code class="directive"><a href="/mod/core.html#sendbuffersize">SendBufferSize</a></code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess directive then the respective value is inherited from the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier main server. (That is, inherited from whatever the final
60a4b2c422dcbb08a554fb193105c08da592718bpoirier setting of that value is in the main server.)</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>The "lookup defaults" that define the default directory
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess permissions for a vhost are merged with those of the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier main server. This includes any per-directory configuration
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess information for any module.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>The per-server configs for each module from the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier main server are merged into the vhost server.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </ol>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>Essentially, the main server is treated as "defaults" or a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess "base" on which to build each vhost. But the positioning of
60a4b2c422dcbb08a554fb193105c08da592718bpoirier these main server definitions in the config file is largely
60a4b2c422dcbb08a554fb193105c08da592718bpoirier irrelevant -- the entire config of the main server has been
60a4b2c422dcbb08a554fb193105c08da592718bpoirier parsed when this final merging occurs. So even if a main server
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess definition appears after a vhost definition it might affect the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess vhost definition.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>If the main server has no <code>ServerName</code> at this
9bcfc3697a91b5215893a7d0206865b13fc72148nd point, then the hostname of the machine that <code class="program"><a href="/programs/httpd.html">httpd</a></code>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier is running on is used instead. We will call the <em>main server address
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess set</em> those IP addresses returned by a DNS lookup on the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <code>ServerName</code> of the main server.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>For any undefined <code>ServerName</code> fields, a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess name-based vhost defaults to the address given first in the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>VirtualHost</code> statement defining the vhost.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Any vhost that includes the magic <code>_default_</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess wildcard is given the same <code>ServerName</code> as the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier main server.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5a58787efeb02a1c3f06569d019ad81fd2efa06end</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="hostmatching" id="hostmatching">Virtual Host Matching</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The server determines which vhost to use for a request as
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess follows:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <h3><a name="hashtable" id="hashtable">IP address lookup</a></h3>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>When the connection is first received on some address and port,
60a4b2c422dcbb08a554fb193105c08da592718bpoirier the server looks for all the <code>VirtualHost</code> definitions
60a4b2c422dcbb08a554fb193105c08da592718bpoirier that have the same IP address and port.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>If there are no exact matches for the address and port, then
60a4b2c422dcbb08a554fb193105c08da592718bpoirier wildcard (<code>*</code>) matches are considered.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>If no matches are found, the request is served by the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier main server.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>If there are <code>VirtualHost</code> definitions for
60a4b2c422dcbb08a554fb193105c08da592718bpoirier the IP address, the next step is to decide if we have to
60a4b2c422dcbb08a554fb193105c08da592718bpoirier deal with an IP-based or a name-based vhost.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <h3><a name="ipbased" id="ipbased">IP-based vhost</a></h3>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf <p>If there is exactly one <code>VirtualHost</code> directive
4cb65c31bc681540ea623e1cb2bdd09749fb8d7esf listing the IP address and port combination that was determined
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf to be the best match, no further actions are performed and
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf the request is served from the matching vhost.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <h3><a name="namebased" id="namebased">Name-based vhost</a></h3>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4cb65c31bc681540ea623e1cb2bdd09749fb8d7esf <p>If there are multiple <code>VirtualHost</code> directives listing
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf the IP address and port combination that was determined to be the
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf best match, the "list" in the remaining steps refers to the list of vhosts
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf that matched, in the order they were in the configuration file.</p>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <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
60a4b2c422dcbb08a554fb193105c08da592718bpoirier the SSL client handshake includes the TLS extension with the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier requested hostname, then that hostname is used below just like the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <code>Host:</code> header would be used on a non-SSL connection.
60a4b2c422dcbb08a554fb193105c08da592718bpoirier Otherwise, the first name-based vhost whose address matched is
60a4b2c422dcbb08a554fb193105c08da592718bpoirier used for SSL connections. This is significant because the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier vhost determines which certificate the server will use for the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier connection.</p>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>If the request contains a <code>Host:</code> header field, the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier list is searched for the first vhost with a matching
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <code>ServerName</code> or <code>ServerAlias</code>, and the
60a4b2c422dcbb08a554fb193105c08da592718bpoirier request is served from that vhost. A <code>Host:</code> header
60a4b2c422dcbb08a554fb193105c08da592718bpoirier field can contain a port number, but Apache always ignores it and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess matches against the real port to which the client sent the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess request.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>The first vhost in the config
60a4b2c422dcbb08a554fb193105c08da592718bpoirier file with the specified IP address has the highest priority
60a4b2c422dcbb08a554fb193105c08da592718bpoirier and catches any request to an unknown server name, or a request
60a4b2c422dcbb08a554fb193105c08da592718bpoirier without a <code>Host:</code> header field (such as a HTTP/1.0
60a4b2c422dcbb08a554fb193105c08da592718bpoirier request).</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <h3><a name="persistent" id="persistent">Persistent connections</a></h3>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <p>The <em>IP lookup</em> described above is only done <em>once</em> for a
60a4b2c422dcbb08a554fb193105c08da592718bpoirier particular TCP/IP session while the <em>name lookup</em> is done on
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>every</em> request during a KeepAlive/persistent
60a4b2c422dcbb08a554fb193105c08da592718bpoirier connection. In other words, a client may request pages from
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess different name-based vhosts during a single persistent
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess connection.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <h3><a name="absoluteURI" id="absoluteURI">Absolute URI</a></h3>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>If the URI from the request is an absolute URI, and its
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess hostname and port match the main server or one of the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess configured virtual hosts <em>and</em> match the address and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess port to which the client sent the request, then the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess scheme/hostname/port prefix is stripped off and the remaining
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess relative URI is served by the corresponding main server or
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess virtual host. If it does not match, then the URI remains
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess untouched and the request is taken to be a proxy request.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<h3><a name="observations" id="observations">Observations</a></h3>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <ul>
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf <li>Name-based virtual hosting is a process applied after
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf the server has selected the best matching IP-based virtual
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf host.</li>
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf <li>If you don't care what IP address the client has connected to, use a
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf "*" as the address of every virtual host, and name-based virtual hosting
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf is applied across all configured virtual hosts.</li>
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf <li><code>ServerName</code> and <code>ServerAlias</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess checks are never performed for an IP-based vhost.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf <li>Only the ordering of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess name-based vhosts for a specific address set is significant.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess The one name-based vhosts that comes first in the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess configuration file has the highest priority for its
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess corresponding address set.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <li>Any port in the <code>Host:</code> header field is never used during the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess matching process. Apache always uses the real port to which
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the client sent the request.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf <li>If two vhosts have an address in common, those common addresses
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf act as name-based virtual hosts implicitly. This is new behavior as of
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf 2.3.11.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <li>The main server is only used to serve a request if the IP
60a4b2c422dcbb08a554fb193105c08da592718bpoirier address and port number to which the client connected
60a4b2c422dcbb08a554fb193105c08da592718bpoirier does not match any vhost (including a
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf <code>*</code> vhost). In other words, the main server
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess only catches a request for an unspecified address/port
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess combination (unless there is a <code>_default_</code> vhost
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess which matches that port).</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>You should never specify DNS names in
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>VirtualHost</code> directives because it will force
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess your server to rely on DNS to boot. Furthermore it poses a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess security threat if you do not control the DNS for all the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess domains listed. There's <a href="/dns-caveats.html">more
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess information</a> available on this and the next two
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess topics.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li><code>ServerName</code> should always be set for each
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess vhost. Otherwise A DNS lookup is required for each
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess vhost.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </ul>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5a58787efeb02a1c3f06569d019ad81fd2efa06end</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="tips" id="tips">Tips</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>In addition to the tips on the <a href="/dns-caveats.html#tips">DNS Issues</a> page, here are
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess some further tips:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <ul>
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <li>Place all main server definitions before any
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>VirtualHost</code> definitions. (This is to aid the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess readability of the configuration -- the post-config merging
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess process makes it non-obvious that definitions mixed in around
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess virtual hosts might affect all virtual hosts.)</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </ul>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5a58787efeb02a1c3f06569d019ad81fd2efa06end</div></div>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd<div class="bottomlang">
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/vhosts/details.html" title="English">&nbsp;en&nbsp;</a> |
d05d0eb4ae6d2a5e513fc3bf2555ce33da416634nd<a href="/fr/vhosts/details.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
4b3a8afbfcea8b265d179a122bf40dfedd1ce280takashi<a href="/ko/vhosts/details.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
4b3a8afbfcea8b265d179a122bf40dfedd1ce280takashi<a href="/tr/vhosts/details.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd</div><div id="footer">
9c1260efa52c82c2a58e5b5f20cd6902563d95f5rbowen<p class="apache">Copyright 2011 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>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<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>
5a58787efeb02a1c3f06569d019ad81fd2efa06end</body></html>