details.html.en revision 60a4b2c422dcbb08a554fb193105c08da592718b
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<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<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>
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.3</a> > <a href="./">Virtual Hosts</a></div><div id="page-content"><div id="preamble"><h1>An In-Depth Discussion of Virtual Host Matching</h1>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<p><span>Available Languages: </span><a href="/en/vhosts/details.html" title="English"> en </a> |
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<a href="/fr/vhosts/details.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> |
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd<a href="/ko/vhosts/details.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim<a href="/tr/vhosts/details.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p>
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>
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
709e3a21ba73b8433462959cd56c773454b34441trawick <p>If you want to understand all the details, then you can
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh come back to this page.</p>
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<h2><a name="configparsing" id="configparsing">Configuration File</a></h2>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele <p>There is a <em>main server</em> which consists of all the
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim definitions appearing outside of
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim <p>There are virtual
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim <code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele sections.</p>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele <p>Each <code>VirtualHost</code> directive includes one
dfc515decf0e3a5a980ec4e06af4eb76d4a95440rbowen or more addresses and optional ports.</p>
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 <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>
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele <p>If using name-based vhosts, the address can be specified as
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele other vhost has the explicit address on which the request was
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele received. The corresponding <code>NameVirtualHost</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
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim The wildcard port matches any port.</p>
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>Collectively the
dfc515decf0e3a5a980ec4e06af4eb76d4a95440rbowen entire set of addresses (including multiple
c8e71fab0ea4bc3f8cb07693d6917f6b4644fbdcerikabele results from DNS lookups) are called the vhost's
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 <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>
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>
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>
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh <p>If there are no vhosts defined for an address in a
0d0ba3a410038e179b695446bb149cce6264e0abnd <code>NameVirtualHost</code> directive is ignored at startup and an error is
0d0ba3a410038e179b695446bb149cce6264e0abnd logged.</p>
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
727872d18412fc021f03969b8641810d8896820bhumbedooh address set is important, see below):</p>
5effc8b39fae5cd169d17f342bfc265705840014rbowen NameVirtualHost 111.22.33.44<br />
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen <VirtualHost 111.22.33.44><br />
0d0ba3a410038e179b695446bb149cce6264e0abnd # server A<br />
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd </VirtualHost><br />
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd <VirtualHost 111.22.33.44><br />
5a58787efeb02a1c3f06569d019ad81fd2efa06end # server B<br />
<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#maxkeepaliverequests">MaxKeepAliveRequests</a></code>,
point, then the hostname of the machine that <code class="program"><a href="/programs/httpd.html">httpd</a></code>
<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
<p><span>Available Languages: </span><a href="/en/vhosts/details.html" title="English"> en </a> |
<a href="/fr/vhosts/details.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> |
<a href="/tr/vhosts/details.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p>
<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>