The configuration for named virtual hosts is similar to IP virtual hosts. The example in Listing 5.2 shows two virtual hosts sharing the 192.168.200.2 IP address. Apache will decide to which virtual host to "route" the request based on the value of the Host: header of the HTTP request. It will be compared for a match with the hostname provided by ServerName and any additional hostnames provided by the ServerAlias directives, which are optional. Listing 5.2. Configuring Name-based Virtual Hosts
The NameVirtualHost directive is required to tell Apache that a particular IP address will be used for name-based virtual hosts. You can tell Apache to use any available IP address for name-based virtual hosting with NameVirtualHost * Of course, your DNS servers need to be configured properly so the domains www.example.com, example.com, and web.example.com resolve to the 192.168.200.2 address. |