Alternate Virtual Hosting


UseCanonicalName Off VirtualDocumentRoot /usr/local/apache/vhosts/%0 VirtualScriptAlias \     /usr/local/apache/vhosts/%0/cgi-bin


If you maintain a great number of virtual hosts, it may be desirable to use a different approach for virtual hosting. This is particularly true for ISPs that host thousands of customers, as it would require entering details for each one of the virtual hosts in the configuration file and restarting the server each time a change is required.

The mod_virtualhost_alias allows you to set up a different document root for each virtual host dynamically. This means that the request is mapped to a certain path on the file system based on information from the request itself, such as the IP address or the hostname. This example maps requests for a particular hostname to a path in the file system that includes that hostname (represented by the %0 in the path). Similarly, the VirtualScriptAlias directive allows execution of CGI scripts in a directory path based on the hostname referred to by the request. If a user sends a request for /manual/index.html to the www.example.com host, this directive will map that to /usr/local/apache/vhosts/ www.example.com/manual/index.html.

In a similar manner, you can map IP addresses instead of hostnames, for IP-based virtual hosting using the VirtualDocumentRootIP and VirtualScriptAliasIP directives.

You can decide to map requests based only on parts of the hostname or IP address or based on the port of the request. For that, you can use different %-based sequences, such as %p for the port number, or %1 for the first part of the domain, %2 for the second, and so on.




Apache(c) Phrase Book(c) Essential Code and Commands
Apache Phrasebook
ISBN: 0672328364
EAN: 2147483647
Year: 2006
Pages: 254

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net