Using Apache to Create Virtual Hosts

Downloads
38289.zip

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.

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottYou'll have the opportunity to experience:
• The Microsoft
Technology Roadmap
• Office 365 Implementation
• Hyper-V Optimizing
• Windows 8 Deployment
and much more!

Come See Paul Thurrott & Rod Trent in Person!

Early Registration Now Open

Upcoming Training

Mastering SharePoint 2013: Succeeding, Not Just Surviving

Building on the success of the “Mastering SharePoint 2010” seminars, the presenters have updated the content to cover the latest and greatest SharePoint product: SharePoint 2013. While SharePoint 2013 is relatively new on the marketplace, the presenters have been working with SharePoint 2013 for well over a year, and have implemented it with a number of clients in production environments.

Register Now

Current Issue

May 2013 - The NameTranslate object is useful when you need to translate Active Directory object names between different formats, but it's awkward to use from PowerShell. Here's a PowerShell script that eliminates the awkwardness.

CURRENT ISSUE / ARCHIVE / SUBSCRIBE

Windows Forums

Get answers to questions, share tips, and engage with the Windows Community in our Forums.