From e6e3f47d535876943effc7cd13d30dea3c89b175 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Andr=C3=A9=20Malo?= This document describes when and how to use name-based virtual hosts.
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 +63,28 @@ they are on separate IP addresses. + +
+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.
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
:
@@ -114,14 +141,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>
@@ -140,11 +168,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
first have your DNS server properly configured to map those names to an IP
@@ -160,22 +188,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.
Available Languages: de | diff --git a/docs/manual/vhosts/name-based.html.fr b/docs/manual/vhosts/name-based.html.fr index 0ecffcf9e6..09bfd15386 100644 --- a/docs/manual/vhosts/name-based.html.fr +++ b/docs/manual/vhosts/name-based.html.fr @@ -25,6 +25,8 @@ ko | tr
Ce document décrit quand et comment utiliser des serveurs virtuels par nom.
diff --git a/docs/manual/vhosts/name-based.xml.de b/docs/manual/vhosts/name-based.xml.de index 933e6b8144..a285faa4b6 100644 --- a/docs/manual/vhosts/name-based.xml.de +++ b/docs/manual/vhosts/name-based.xml.de @@ -1,7 +1,7 @@ - + + diff --git a/docs/manual/vhosts/name-based.xml.ja b/docs/manual/vhosts/name-based.xml.ja index 55f0128a82..3b4bc0b1f2 100644 --- a/docs/manual/vhosts/name-based.xml.ja +++ b/docs/manual/vhosts/name-based.xml.ja @@ -1,7 +1,7 @@ - + + +