⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 name-based.html.en

📁 apache 安装教程 apache 安装教程
💻 EN
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">  <head>    <title>Name-based Virtual Hosts</title>  </head>  <!-- Background white, links blue (unvisited), navy (visited), red (active) -->  <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"  vlink="#000080" alink="#FF0000">        <div align="CENTER">      <img src="../images/sub.gif" alt="[APACHE DOCUMENTATION]" />      <h3>Apache HTTP Server Version 1.3</h3>        <p><small><em>Is this the version you want?  For more recent         versions, check our <a href="/docs/">documentation          index</a>.</em></small></p>    </div>    <h1 align="CENTER">Name-based Virtual Host Support</h1><p>This document describes when and how to use name-based virtual hosts.</p><ul><li><a href="#namevip">Name-based vs. IP-based Virtual Hosts</a></li><li><a href="#using">Using Name-based Virtual Hosts</a></li><li><a href="#compat">Compatibility With Older Browsers</a></li></ul><p>See also: <a href="examples.html">Virtual Host examples for commonsetups</a>, <a href="ip-based.html">IP-based Virtual Host Support</a>,<a href="details.html">An In-Depth Discussion of Virtual HostMatching</a>, and <a href="mass.html">Dynamically configured massvirtual hosting</a>.</p><hr /><h2><a name="namevip">Name-based vs. IP-based Virtual Hosts</a></h2><p>IP-based virtual hosts use the IP address of the connection todetermine the correct virtual host to serve.  Therefore you need tohave a separate IP address for each host.  With name-based virtualhosting, the server relies on the client to report the hostname aspart of the HTTP headers.  Using this technique, many different hostscan share the same IP address.</p><p>Name-based virtual hosting is usually simpler, since you needonly configure your DNS server to map each hostname to the correctIP address and then configure the Apache HTTP Server to recognizethe different hostnames.  Name-based virtual hosting also easesthe demand for scarce IP addresses.  Therefore you should usename-based virtual hosting unless there is a specific reason tochoose IP-based virtual hosting.  Some reasons why you might considerusing IP-based virtual hosting:</p><ul> <li>Some ancient clients are not compatible with name-based virtualhosting.  For name-based virtual hosting to work, the client must sendthe HTTP Host header.  This is required by HTTP/1.1, and isimplemented by all modern HTTP/1.0 browsers as an extension.  If youneed to support obsolete clients and still use name-based virtualhosting, a possible technique is discussed at the end of thisdocument.</li><li>Name-based virtual hosting cannot be used with SSL secure serversbecause of the nature of the SSL protocol.</li><li>Some operating systems and network equipment implement bandwidthmanagement techniques that cannot differentiate between hosts unlessthey are on separate IP addresses.</li></ul><h2><a name="using">Using Name-based Virtual Hosts</a></h2><table border="1"><tr><td align="top"><strong>Related Directives</strong><br><br><a href="../mod/core.html#documentroot">DocumentRoot</a><br /><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a><br /><a href="../mod/core.html#serveralias">ServerAlias</a><br /><a href="../mod/core.html#servername">ServerName</a><br /><a href="../mod/core.html#serverpath">ServerPath</a><br /><a href="../mod/core.html#virtualhost">VirtualHost</a><br /></td></tr></table><p>To use name-based virtual hosting, you must designate the IPaddress (and possibly port) on the server that will be acceptingrequests for the hosts.  This is configured using the <ahref="../mod/core.html#namevirtualhost">NameVirtualHost</a> directive.In the normal case where any and all IP addresses on the server shouldbe used, you can use <code>*</code> as the argument to<code>NameVirtualHost</code>.  (<code>NameVirtualHost *</code> willwork only in version 1.3.13 and later.)  Note that mentioning an IPaddress in a <code>NameVirtualHost</code> directive does notautomatically make the server listen to that IP address.  See <ahref="../bind.html">Setting which addresses and ports Apache uses</a>for more details.  In addition, any IP address specified here must beassociated with a network interface on the server.</p><p>The next step is to create a <ahref="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a> block foreach different host that you would like to serve.  The argument to the<code>&lt;VirtualHost&gt;</code> directive should be the same as theargument to the <code>NameVirtualHost</code> directive (ie, an IPaddress, or <code>*</code> for all addresses).  Inside each<code>&lt;VirtualHost&gt;</code> block, you will need at minimum a <ahref="../mod/core.html#servername">ServerName</a> directive todesignate which host is served and a <ahref="../mod/core.html#documentroot">DocumentRoot</a> directive toshow where in the filesystem the content for that host lives.</p><p>If you are adding virtual hosts to an existing web server, youmust also create a &lt;VirtualHost&gt; block for the existing host.The <code>ServerName</code> and <code>DocumentRoot</code> included inthis virtual host should be the same as the global<code>ServerName</code> and <code>DocumentRoot</code>.  List thisvirtual host first in the configuration file so that it will act asthe default host.</p><p>For example, suppose that you are serving the domain<samp>www.domain.tld</samp> and you wish to add the virtual host<samp>www.otherdomain.tld</samp>, which points at the same IP address.Then you simply add the following to <code>httpd.conf</code>:</p><pre>    NameVirtualHost *    &lt;VirtualHost *&gt;    ServerName www.domain.tld    DocumentRoot /www/domain    &lt;/VirtualHost&gt;    &lt;VirtualHost *&gt;    ServerName www.otherdomain.tld    DocumentRoot /www/otherdomain    &lt;/VirtualHost&gt;</pre><p>You can alternatively specify an explicit IP address in place ofthe * in both the <code>NameVirtualHost</code> and<code>&lt;VirtualHost&gt;</code> directives.  The IP address isrequired in version 1.3.12 and earlier.</p><p>Many servers want to be accessible by more than one name.  This ispossible with the <ahref="../mod/core.html#serveralias"><code>ServerAlias</code></a>directive, placed inside the &lt;VirtualHost&gt; section. Forexample if you add this to the first &lt;VirtualHost&gt; blockabove</p> <blockquote><code> ServerAlias domain.tld *.domain.tld</code></blockquote><p>then requests for all hosts in the <code>domain.tld</code> domainwill be served by the <code>www.domain.tld</code> virtual host.  Thewildcard characters * and ? can be used to match names.  Of course,you can't just make up names and place them in <code>ServerName</code>or <code>ServerAlias</code>.  You must first have your DNS serverproperly configured to map those names to an IP address associatedwith your server.</p><p>Finally, you can fine-tune the configuration of the virtual hostsby placing other directives inside the<code>&lt;VirtualHost&gt;</code> containers.  Most directives can beplaced in these containers and will then change the configuration onlyof the relevant virtual host.  To find out if a particular directiveis allowed, check the <ahref="../mod/directive-dict.html#Context">Context</a> of thedirective.  Configuration directives set in the <em>main servercontext</em> (outside any <code>&lt;VirtualHost&gt;</code> container)will be used only if they are not overriden by the virtual hostsettings.</p><p>Now when a request arrives, the server will first check if it isusing an IP address that matches the <code>NameVirtualHost</code>.  Ifit is, then it will look at each <code>&lt;VirtualHost&gt;</code>section with a matching IP address and try to find one where the<code>ServerName</code> or <code>ServerAlias</code> matches therequested hostname.  If it finds one, then it uses the configurationfor that server.  If no matching virtual host is found, then<strong>the first listed virtual host</strong> that matches the IPaddress will be used.</p><p>As a consequence, the first listed virtual host is the<em>default</em> virtual host.  The <code>DocumentRoot</code> from the<em>main server</em> will <strong>never</strong> be used when an IPaddress matches the <code>NameVirtualHost</code> directive.  If youwould like to have a special configuration for requests that do notmatch any particular virtual host, simply put that configuration in a<code>&lt;VirtualHost&gt;</code> container and list it first in theconfiguration file.</p><h2><a name="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>    <p>There is a possible workaround with the <a    href="../mod/core.html#serverpath"><code>ServerPath</code></a>    directive, albeit a slightly cumbersome one:</p>    <p>Example configuration:</p><pre>    NameVirtualHost 111.22.33.44    &lt;VirtualHost 111.22.33.44&gt;    ServerName www.domain.tld    ServerPath /domain    DocumentRoot /web/domain    &lt;/VirtualHost&gt;</pre>    <p>What does this mean? It means that a request for any URI    beginning with "<samp>/domain</samp>" will be served from the    virtual host <samp>www.domain.tld</samp> This means that the    pages can be accessed as    <code>http://www.domain.tld/domain/</code> for all clients,    although clients sending a <samp>Host:</samp> 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    <samp>http://www.domain.tld/domain/</samp> Then, in the virtual    host's pages, be sure to use either purely relative links    (<em>e.g.</em>, "<samp>file.html</samp>" or    "<samp>../icons/image.gif</samp>" or links containing the    prefacing <samp>/domain/</samp> (<em>e.g.</em>,    "<samp>http://www.domain.tld/domain/misc/file.html</samp>" or    "<samp>/domain/misc/file.html</samp>").</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>    <p>See also: <a href="examples.html#serverpath">ServerPath    configuration example</a></p>        <hr />    <h3 align="CENTER">Apache HTTP Server Version 1.3</h3>    <a href="./"><img src="../images/index.gif" alt="Index" /></a>    <a href="../"><img src="../images/home.gif" alt="Home" /></a>  </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -