Recipe 4.5 Mixing Address-Based and Name-Based Virtual Hosts

Problem

You have multiple IP addresses assigned to your system, and you want to support more than one web site on each address.

Solution

Provide a NameVirtualHost directive for each IP address, and proceed as you did with a single IP address:

ServerName 127.0.0.1 NameVirtualHost 10.0.0.1 NameVirtualHost 10.0.0.2 <VirtualHost 10.0.0.1>     ServerName TheSmiths.name     DocumentRoot "C:/Apache/Sites/TheSmiths" </VirtualHost> <VirtualHost 10.0.0.1>     ServerName JohnSmith.name     DocumentRoot "C:/Apache/Sites/JustJohnSmith" </VirtualHost> <VirtualHost 10.0.0.2>     ServerName TheFergusons.name     DocumentRoot "C:/Apache/Sites/TheFergusons" </VirtualHost> <VirtualHost 10.0.0.2>     ServerName DoriFergusons.name     DocumentRoot "C:/Apache/Sites/JustDoriFerguson" </VirtualHost>

Discussion

Using the address of the server, rather than the wildcard * argument, makes the virtual hosts listen only to that IP address. However, you should notice that the argument to <VirtualHost> still must match the argument to the NameVirtualHost with which they are connected.

See Also

  • http://httpd.apache.org/docs/vhosts/



Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

Similar book on Amazon

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