📄 details.html.en
字号:
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">Hash table lookup</a></h3> <p>When the connection is first made by a client, the IP address to which the client connected is looked up in the internal IP hash table.</p> <p>If the lookup fails (the IP address wasn't found) the request is served from the <code>_default_</code> vhost if there is such a vhost for the port to which the client sent the request. If there is no matching <code>_default_</code> vhost the request is served from the main_server.</p> <p>If the IP address is not found in the hash table then the match against the port number may also result in an entry corresponding to a <code>NameVirtualHost *</code>, which is subsequently handled like other name-based vhosts.</p> <p>If the lookup succeeded (a corresponding list for the IP address was found) the next step is to decide if we have to deal with an IP-based or a name-base vhost.</p> <h3><a name="ipbased" id="ipbased">IP-based vhost</a></h3> <p>If the entry we found has an empty name list then we have found an IP-based vhost, no further actions are performed and the request is served from that vhost.</p> <h3><a name="namebased" id="namebased">Name-based vhost</a></h3> <p>If the entry corresponds to a name-based vhost the name list contains one or more vhost structures. This list contains the vhosts in the same order as the <code>VirtualHost</code> directives appear in the config file.</p> <p>The first vhost on this list (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.</p> <p>If the client provided a <code>Host:</code> header field the list is searched for a matching vhost and the first hit on a <code>ServerName</code> or <code>ServerAlias</code> is taken and the request is served from that vhost. A <code>Host:</code> header field can contain a port number, but Apache always matches against the real port to which the client sent the request.</p> <p>If the client submitted a HTTP/1.0 request without <code>Host:</code> header field we don't know to what server the client tried to connect and any existing <code>ServerPath</code> is matched against the URI from the request. The first matching path on the list is used and the request is served from that vhost.</p> <p>If no matching vhost could be found the request is served from the first vhost with a matching port number that is on the list for the IP to which the client connected (as already mentioned before).</p> <h3><a name="persistent" id="persistent">Persistent connections</a></h3> <p>The IP lookup described above is only done <em>once</em> for a particular TCP/IP session while the name lookup 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> and <code>ServerPath</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>For security reasons the port number given in a <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 a <code>ServerPath</code> directive exists which is a prefix of another <code>ServerPath</code> directive that appears later in the configuration file, then the former will always be matched and the latter will never be matched. (That is assuming that no <code>Host:</code> header field was available to disambiguate the two.)</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.</li> <li>The main_server is only used to serve a request if the IP address and port number to which the client connected is unspecified and does not match any other 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> <li>Avoid <code>ServerPaths</code> which are prefixes of other <code>ServerPaths</code>. If you cannot avoid this then you have to ensure that the longer (more specific) prefix vhost appears earlier in the configuration file than the shorter (less specific) prefix (<em>i.e.</em>, "ServerPath /abc" should appear after "ServerPath /abc/def").</li> </ul></div></div><div class="bottomlang"><p><span>Available Languages: </span><a href="../en/vhosts/details.html" title="English"> en </a> |<a href="../ko/vhosts/details.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p></div><div id="footer"><p class="apache">Copyright 2007 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -