Configuring Virtual Hosts
A virtual host is simply a Web site with its own domain name hosted by an Apache server. By default, Apache is set up to serve just one virtual host. However, you can add more virtual hosts. As a result, a single Apache server is able to host more than one Web site.
For example, if I were so inclined, I might set up an Apache server to host my own personal Web site (www.lowewriter.com) that has information about my books and a second Web site (www.hauntedlowes.com) that has information about my favorite hobby, decorating my house for Halloween. Both of these Web sites could be implemented as virtual hosts on a single Apache server.
To configure a virtual host (including the default virtual host if you have only one), you use the Virtual Hosts tab of the HTTP configuration tool.
Configuring the default host
Even if you don't plan on creating additional virtual hosts, you can still use the Virtual Hosts tab to configure the default virtual host for your Web site. To do so, select the virtual host in the Virtual Hosts list and click the Edit button. This brings up the Virtual Host Properties dialog box.
From this dialog box, you can configure a variety of important settings for the virtual host:
- Virtual Host Name: The name you use to refer to the virtual host. For the default virtual host, the default name is - drum roll, please - Default Virtual Host. (Don't blame me, it isn't my fault.)
- Document Root Directory: This is the file system location that contains the HTML documents for the Web site. The default is /var/www/html, but you can specify a different location if you want to store your HTML files somewhere else.
- Webmaster E-Mail Address: Each virtual host can have its own Webmaster e-mail address. If you leave this option blank, the address specified for the main HTTP configuration is used.
- Host Information: This section of the dialog box lets you specify what HTTP requests should be serviced by this virtual host. In most cases, you should leave this set to the default setting, Handle All Remaining Unhandled Requests.
You can use the other tabs of the Virtual Host Properties dialog box to configure additional options. Here, you can set the following options:
- Directory Page Search List: This list specifies the default page for the Web site. The default page is displayed if the user doesn't indicate a specific page to retrieve. Then, Apache looks for each of the pages listed in the Directory Page Search list and displays the first one it finds. You can use the Add, Edit, and Delete buttons to modify this list.
- Error Pages: This list lets you change the default error pages that are displayed when an HTTP error occurs. The most common HTTP error, Not Found, happens when the user requests a page that doesn't exist. If you want to create a custom error page to let the user know that the page doesn't exist or that some other error has occurred, this is the place to do it.
Creating a virtual host
If you want to host more than one Web site on an Apache server, you can create additional virtual hosts. Just follow these steps:
- Click the Add button on the Virtual Hosts tab of the HTTP configuration tool.
This brings up the Virtual Host Properties dialog box.
- In the Host Information section, choose Name Based Virtual Host in the drop-down list.
The Virtual Host Properties dialog box morphs into the dialog box.
- Enter the IP address and the host name for the virtual host.
The IP address is usually the IP address assigned to the Apache server, and the host name is the DNS name used to access the virtual host.
- If you want to provide an alias for the virtual host, click the Add
button, enter the alias name, and click OK.
An alias is often used for Web sites that are used on an intranet rather than on public Web sites. For example, if you're setting up an intranet Web site for your company suggestion box, the full DNS name for the virtual host might be suggestionbox.mycompany.com. But if you provide just suggestionbox as an alias, users can access the suggestion box Web site by using suggestionbox rather than suggestionbox. mycompany.com as the Web site address.
- Use the other tabs of the Virtual Host Properties dialog box to configure additional options.
For example, you might want to use the Page Options tab to change the directory page search list or designate custom error pages.
- Click OK.
The virtual host is created. You're returned to the HTTP configuration tool, and the new virtual host will appear in the Virtual Hosts list.
In this tutorial:
- Managing Linux Systems
- Planning a Linux Server Installation
- Installing Fedora 7
- Getting Used to Linux
- Understanding the file system
- On Again, Off Again
- Using GNOME
- Managing User Accounts
- Linux Network Configuration
- Restarting Your Network
- Working with Network Configuration Files
- The ifcfg files
- The resolv.conf file
- DHCP and DNS
- Configuring DHCP
- Running a DNS Server
- Running Apache
- Starting and Stopping Apache
- Confirming that Apache Is Running
- Using the HTTP Configuration Tool
- Restricting Access to an Apache Server
- Configuring Virtual Hosts
- Setting the Apache User Account
- Running Sendmail
- Installing Sendmail
- Modifying sendmail.mc
- Using SpamAssassin
- Using the Mail Console Client
- Running FTP
- Starting the vsftpd Service
- Configuring FTP