Return-Path: Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: (qmail 60204 invoked from network); 8 Dec 2010 16:52:56 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Dec 2010 16:52:56 -0000 Received: (qmail 57107 invoked by uid 500); 8 Dec 2010 16:52:56 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 56934 invoked by uid 500); 8 Dec 2010 16:52:55 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 56926 invoked by uid 99); 8 Dec 2010 16:52:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Dec 2010 16:52:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Dec 2010 16:52:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A9609238890B; Wed, 8 Dec 2010 16:52:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1043516 - /httpd/httpd/trunk/docs/manual/vhosts/name-based.xml Date: Wed, 08 Dec 2010 16:52:34 -0000 To: cvs@httpd.apache.org From: covener@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101208165234.A9609238890B@eris.apache.org> Author: covener Date: Wed Dec 8 16:52:34 2010 New Revision: 1043516 URL: http://svn.apache.org/viewvc?rev=1043516&view=rev Log: Move the description of how a name-based vhost is picked to the top instead of burying it. Reword some other "default vhost" references. Modified: httpd/httpd/trunk/docs/manual/vhosts/name-based.xml Modified: httpd/httpd/trunk/docs/manual/vhosts/name-based.xml URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/vhosts/name-based.xml?rev=1043516&r1=1043515&r2=1043516&view=diff ============================================================================== --- httpd/httpd/trunk/docs/manual/vhosts/name-based.xml (original) +++ httpd/httpd/trunk/docs/manual/vhosts/name-based.xml Wed Dec 8 16:52:34 2010 @@ -39,10 +39,9 @@ determine the correct virtual host to serve. Therefore you need to have a separate IP address for each host.

-

With name-based virtual - hosting, the server relies on the client to report the hostname as - part of the HTTP headers. Using this technique, many different hosts - can share the same IP address.

+

With name-based virtual hosting, the server relies on the client to + report the hostname as part of the HTTP headers. Using this technique, + many different hosts can share the same IP address.

Name-based virtual hosting is usually simpler, since you need only configure your DNS server to map each hostname to the correct @@ -63,6 +62,30 @@ they are on separate IP addresses. + + + +

How the server selects the proper name-based virtual host + +

It is important to recognize that the first step in name-based virtual + host resolution is IP-based resolution. Name-based virtual host + resolution only chooses the most appropriate name-based virtual host + after narrowing down the candidates to the best IP-based match. Using a wildcard (*) + for the IP address in all of the NameVirtualHost and VirtualHost directives makes this + IP-based mapping irrelevant.

+ +

When a request arrives, the server will first check if it is using + an IP address that matches exactly any NameVirtualHost. If it is, then it will look at each VirtualHost section with a (literal) matching + IP address and try to find one where the ServerName or ServerAlias matches the requested + hostname. If it finds one, then it uses the configuration for that server.

+ +

If no matching ServerName or ServerAlias is found in the + set of virtual hosts matching the NameVirtualHost directive, then + the first listed virtual host that matches the IP + address will be used.

Using Name-based Virtual Hosts @@ -113,20 +136,23 @@ lives.

Main host goes away -

If you are adding virtual hosts to an existing web server, you - must also create a VirtualHost block for the existing host. The ServerName and DocumentRoot included in this virtual host should be the - same as the global ServerName and - DocumentRoot. List this virtual - host first in the configuration file so that it will act as the default - host.

+

Any request that doesn't match an existing VirtualHost is handled by the global + server configuration, regardless of the hostname or ServerName.

+ +

When you add a name-based virtual host to an existing server, and + the virtual host arguments match preexisting IP and port combinations, + requests will now be handled by an explicit virtual host. In this case, + it's usually wise to create a default virtual host + with a ServerName matching that of + the base server. New domains on the same interface and port, but + requiring separate configurations, can then be added as subsequent (non-default) + virtual hosts.

For example, suppose that you are serving the domain - www.domain.tld and you wish to add the virtual host - www.otherdomain.tld, which points at the same IP address. + www.example.com and you wish to add the virtual host + other.example.com, which points at the same IP address. Then you simply add the following to httpd.conf:

@@ -134,14 +160,15 @@
<VirtualHost *:80>
- ServerName www.domain.tld
- ServerAlias domain.tld *.domain.tld
+ # This first-listed virtual host is also the default for *:80 + ServerName www.example.com
+ ServerAlias example.com *.example.com
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
- ServerName www.otherdomain.tld
+ ServerName other.example.com
DocumentRoot /www/otherdomain
</VirtualHost>
@@ -164,11 +191,11 @@ web site:

- ServerAlias domain.tld *.domain.tld + ServerAlias example.com *.example.com -

then requests for all hosts in the domain.tld domain will - be served by the www.domain.tld virtual host. The wildcard +

then requests for all hosts in the example.com domain will + be served by the www.example.com virtual host. The wildcard characters * and ? can be used to match names. Of course, you can't just make up names and place them in ServerName or ServerAlias. You must @@ -186,25 +213,6 @@ container) will be used only if they are not overridden by the virtual host settings.

-

Now when a request arrives, the server will first check if it is using - an IP address that matches the NameVirtualHost. If it is, then it will look at each VirtualHost section with a matching - IP address and try to find one where the ServerName or ServerAlias matches the requested - hostname. If it finds one, then it uses the configuration for that server. - If no matching virtual host is found, then the first listed virtual - host that matches the IP address will be used.

- -

As a consequence, the first listed virtual host is the default - virtual host. The DocumentRoot from - the main server will never be used when an IP - address matches the NameVirtualHost - 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 VirtualHost - container and list it first in the configuration file.

-