Configuring IP-based Virtual Hosting


The example in Listing 5.1 shows three IP-based virtual hosts serving content for three websites: www.example.com, a staging version of www.example.com, and www.example.net. The ServerName directive inside each container will be used for constructing self-referential URLs. The DocumentRoot directive specifies a different location for the website's content for each virtual host. It is also possible to log requests and errors for each virtual host to a different file. This can be done by placing logging directives such as transferLog and ErrorLog inside the virtual host container, as explained in Chapter 3.

The addresses and ports listed inside the opening tag of a <VirtualHost> definition will not have any effect on what addresses or ports Apache listens to, so you still need to provide the appropriate Listen directives. If no port is specified in a <VirtualHost> definition, the one specified in the most recent Apache directive will be used. It is also possible to specify a wildcard "*" to listen for requests in all ports that Apache is listening in, as shown in the example.net virtual host.

Listing 5.1. Configuring IP-Based Virtual Hosts

Listen 8080 Listen 80 <VirtualHost 192.168.200.2>     ServerName www.example.com     DocumentRoot /usr/local/apache/sites/example.com </VirtualHost> <VirtualHost 192.168.200.2:8080>     ServerName www.example.com     DocumentRoot /usr/local/apache/sites/staging </VirtualHost> <VirtualHost 192.168.200.4:*>     ServerName www.example.net     DocumentRoot /usr/local/apache/sites/example.net </VirtualHost>




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