From: Eric Covener
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.
+
+
+
+ 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 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.ServerAlias
matches the requested
+ hostname. If it finds one, then it uses the configuration for that server.
If you are adding virtual hosts to an existing web server, you
- must also create a
Any request that doesn't match an existing
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
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
:
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 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 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