Книга: Fedora™ Unleashed, 2008 edition

Name-Based Virtual Hosts

Name-Based Virtual Hosts

Name-based virtual hosts enable you to run more than one host on the same IP address. You must add the names to your DNS as CNAMEs of the machine in question. When an HTTP client (web browser) requests a document from your server, it sends with the request a variable indicating the server name from which it's requesting the document. Based on this variable, the server determines from which of the virtual hosts it should serve content.

NOTE

Some older browsers are unable to see name-based virtual hosts because this is a feature of HTTP 1.1 and the older browsers are strictly HTTP 1.0-compliant. However, many other older browsers are partially HTTP 1.1-compliant, and this is one of the parts of HTTP 1.1 that most browsers have supported for a while.

Name-based virtual hosts require just one step more than IP address-based virtual hosts. You must first indicate which IP address has the multiple DNS names on it. This is done with the NameVirtualHost directive:

NameVirtualHost 212.85.67.67

You must then have a section for each name on that address, setting the configuration for that name. As with IP-based virtual hosts, you need to set only those configurations that must be different for the host. You must set the ServerName directive because it's the only thing that distinguishes one host from another:

<VirtualHost 212.85.67.67>
 ServerName bugserver.gnulix.org
 ServerAlias bugserver
 DocumentRoot /home/bugserver/htdocs
 ScriptAlias /home/bugserver/cgi-bin
 TransferLog /home/bugserver/logs/access_log
</VirtualHost>
<VirtualHost 212.85.67.67>
 ServerName pts.gnulix.org
 ServerAlias pts
 DocumentRoot /home/pts/htdocs
 ScriptAlias /home/pts/cgi-bin
 TransferLog /home/pts/logs/access_log
 ErrorLog /home/pts/logs/error_log
</VirtualHost>

TIP

If you're hosting websites on an intranet or internal network, users are likely to use the shortened name of the machine rather than the FQDN. For example, users might type http://bugserver/index.html in their browser location fields rather than http://bugserver.gnulix.org/index.html. In that case, Apache would not recognize that those two addresses should go to the same virtual host. You could get around this by setting up VirtualHost directives for both bugserver and bugserver.gnulix.org, but the easy way around it is to use the ServerAlias directive, which lists all valid aliases for the machine:

ServerAlias bugserver

For more information about VirtualHost, refer to the help system on http://localhost/_manual.

Оглавление книги

Оглавление статьи/книги

Генерация: 4.673. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз