Many organizations use the Apache HTTP Server to host only one Web site, but hosting multiple Web sites from one server or a server farm isn't uncommon, especially for large businesses. Apache refers to this type of implementation as virtual hosting. The key idea is to configure Apache to respond according to the Web site that a client is trying to view.
Two types of virtual hosting are possible: IP-based and name-based. Both work equally well, but IP-based virtual hosting requires that each Web site have a unique IP address associated with it. With name-based virtual hosting, Apache determines which Web site a client wants to view, according to information that the client browser provides.
Configuring IP-based virtual hosting is surprisingly easy. The first step is to create a <VirtualHost> directive block containing the Web site's IP address. For example, suppose you have two Web sites—www.example.com and finance.example.com—with the IP addresses 192.168.0.100 and 192.168.0.101, respectively. Configure Apache to define two <VirtualHost> blocks, each of which will contain directives configuring the specified Web site, as Listing A shows.
You also need to configure your Web server to listen to these IP addresses. To do so, configure Windows 2000 to listen to each address through the Control Panel Network and Dial-Up Connections applet's Local Area Connection setting.
Name-based virtual hosting is more popular than IP-based virtual hosting because the Web server can host one, several, or hundreds of Web sites through only one IP address. To configure name-based virtual hosting, you need to specify the NameVirtualHost directive before you specify the <VirtualHost> blocks, as Listing B shows. Note the use of the asterisk (*) with the NameVirtualHost and <VirtualHost> directives. This wildcard character specifies that Apache should listen for packets on all network interfaces. Alternatively, you can specify the IP address that Apache should use, as Listing C shows. Specifying the address is useful when debugging virtual hosting problems. Also note that when using name-based virtual hosting, you need to configure your DNS server to return the IP address 192.168.0.100 for both www.example.com and finance.example.com because you aren't relying on IP addresses to differentiate the Web sites.