Раздел 3. Apache Virtual Host documentation RU EN Пункт 28. Name-based Virtual Hosts This document describes when and how to use name-based virtual hosts. Name-based vs. IP-based Virtual HostsIP-based virtual hosts use the IP address of the connection to 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. Name-based virtual hosting is usually simpler, since you need only configure your DNS server to map each hostname to the correct IP address and then configure the Apache HTTP Server to recognize the different hostnames. Name-based virtual hosting also eases the demand for scarce IP addresses. Therefore you should use name-based virtual hosting unless you are using equipment that explicitly demands IP-based hosting. Historical reasons for IP-based virtual hosting based on client support are no longer applicable to a general-purpose web server. Name-based virtual hosting builds off of the IP-based virtual host selection algorithm, meaning that searches for the proper server name occur only between virtual hosts that have the best IP-based address. How the server selects the proper name-based virtual hostIt 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 VirtualHost directives makes this IP-based mapping irrelevant. When a request arrives, the server will find the best (most specific) matching
If you omit the The default name-based vhost for an IP and port combinationIf no matching ServerName or ServerAlias is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used. Using Name-based Virtual Hosts
The first step is to create a Main host goes away 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 ServerName inheritance It is best to always explicitly list a If a For example, suppose that you are serving the domain
<VirtualHost *:80> # This first-listed virtual host is also the default for *:80 ServerName www.example.com ServerAlias example.com DocumentRoot "/www/domain" </VirtualHost> <VirtualHost *:80> ServerName other.example.com DocumentRoot "/www/otherdomain" </VirtualHost> You can alternatively specify an explicit IP address in place of the
Many servers want to be accessible by more than one name. This is
possible with the ServerAlias example.com *.example.com then requests for all hosts in the Name-based virtual hosts for the best-matching set of The complete list of names in the Finally, you can fine-tune the configuration of the virtual hosts
by placing other directives inside the |
![]() |