?? name-based.html.en
字號:
<br /> <VirtualHost *:80><br /> <span class="indent">ServerName www.otherdomain.tld<br /> DocumentRoot /www/otherdomain<br /> </span> </VirtualHost><br /> </code></p></div> <p>You can alternatively specify an explicit IP address in place of the <code>*</code> in both the <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code> and <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> directives. For example, you might want to do this in order to run some name-based virtual hosts on one IP address, and either IP-based, or another set of name-based virtual hosts on another address.</p> <p>Many servers want to be accessible by more than one name. This is possible with the <code class="directive"><a href="../mod/core.html#serveralias">ServerAlias</a></code> directive, placed inside the <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> section. For example in the first <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> block above, the <code class="directive"><a href="../mod/core.html#serveralias">ServerAlias</a></code> directive indicates that the listed names are other names which people can use to see that same web site:</p> <div class="example"><p><code> ServerAlias domain.tld *.domain.tld </code></p></div> <p>then requests for all hosts in the <code>domain.tld</code> domain will be served by the <code>www.domain.tld</code> virtual host. The wildcard characters <code>*</code> and <code>?</code> can be used to match names. Of course, you can't just make up names and place them in <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code> or <code>ServerAlias</code>. You must first have your DNS server properly configured to map those names to an IP address associated with your server.</p> <p>Finally, you can fine-tune the configuration of the virtual hosts by placing other directives inside the <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> containers. Most directives can be placed in these containers and will then change the configuration only of the relevant virtual host. To find out if a particular directive is allowed, check the <a href="../mod/directive-dict.html#Context">Context</a> of the directive. Configuration directives set in the <em>main server context</em> (outside any <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> container) will be used only if they are not overridden by the virtual host settings.</p> <p>Now when a request arrives, the server will first check if it is using an IP address that matches the <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code>. If it is, then it will look at each <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> section with a matching IP address and try to find one where the <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code> or <code>ServerAlias</code> matches the requested hostname. If it finds one, then it uses the configuration for that server. If no matching virtual host is found, then <strong>the first listed virtual host</strong> that matches the IP address will be used.</p> <p>As a consequence, the first listed virtual host is the <em>default</em> virtual host. The <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> from the <em>main server</em> will <strong>never</strong> be used when an IP address matches the <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code> directive. If you would like to have a special configuration for requests that do not match any particular virtual host, simply put that configuration in a <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> container and list it first in the configuration file.</p></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="compat" id="compat">Compatibility with Older Browsers</a></h2> <p>As mentioned earlier, there are some clients who do not send the required data for the name-based virtual hosts to work properly. These clients will always be sent the pages from the first virtual host listed for that IP address (the <cite>primary</cite> name-based virtual host).</p> <div class="note"><h3>How much older?</h3> <p>Please note that when we say older, we really do mean older. You are very unlikely to encounter one of these browsers in use today. All current versions of any browser send the <code>Host</code> header as required for name-based virtual hosts.</p> </div> <p>There is a possible workaround with the <code class="directive"><a href="../mod/core.html#serverpath">ServerPath</a></code> directive, albeit a slightly cumbersome one:</p> <p>Example configuration:</p> <div class="example"><p><code> NameVirtualHost 111.22.33.44<br /> <br /> <VirtualHost 111.22.33.44><br /> <span class="indent"> ServerName www.domain.tld<br /> ServerPath /domain<br /> DocumentRoot /web/domain<br /> </span> </VirtualHost><br /> </code></p></div> <p>What does this mean? It means that a request for any URI beginning with "<code>/domain</code>" will be served from the virtual host <code>www.domain.tld</code>. This means that the pages can be accessed as <code>http://www.domain.tld/domain/</code> for all clients, although clients sending a <code>Host:</code> header can also access it as <code>http://www.domain.tld/</code>.</p> <p>In order to make this work, put a link on your primary virtual host's page to <code>http://www.domain.tld/domain/</code>. Then, in the virtual host's pages, be sure to use either purely relative links (<em>e.g.</em>, "<code>file.html</code>" or "<code>../icons/image.gif</code>") or links containing the prefacing <code>/domain/</code> (<em>e.g.</em>, "<code>http://www.domain.tld/domain/misc/file.html</code>" or "<code>/domain/misc/file.html</code>").</p> <p>This requires a bit of discipline, but adherence to these guidelines will, for the most part, ensure that your pages will work with all browsers, new and old.</p></div></div><div class="bottomlang"><p><span>Available Languages: </span><a href="../de/vhosts/name-based.html" hreflang="de" rel="alternate" title="Deutsch"> de </a> |<a href="../en/vhosts/name-based.html" title="English"> en </a> |<a href="../es/vhosts/name-based.html" hreflang="es" rel="alternate" title="Espa駉l"> es </a> |<a href="../ja/vhosts/name-based.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |<a href="../ko/vhosts/name-based.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p></div><div id="footer"><p class="apache">Copyright 1995-2005 The Apache Software Foundation or its licensors, as applicable.<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 + -