- Table of Contents
- Copyright
- About the Lead Authors
- About the Contributing Authors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- I. Red Hat Linux Installation and User Services
- Chapter 1. Introduction to Red Hat Linux
- Chapter 2. Installation of Your Red Hat System
- Chapter 3. LILO and Other Boot Managers
- Chapter 4. Configuring the X Window System, Version 11
- Chapter 5. Window Managers
- Chapter 6. Connecting to the Internet
- Chapter 7. IRC, ICQ, and Chat Clients
- Chapter 8. Using Multimedia and Graphics Clients
- II. Configuring Services
- Chapter 9. System Startup and Shutdown
- Chapter 10. SMTP and Protocols
- Chapter 11. FTP
- Chapter 12. Apache Server
- Chapter 13. Internet News
- Chapter 14. Domain Name Service and Dynamic Host Configuration Protocol
- Chapter 15. NIS: Network Information Service
- Chapter 16. NFS: Network Filesystem
- Chapter 17. Samba
- III. System Administration and Management
- Chapter 18. Linux Filesystems, Disks, and Other Devices
- Chapter 19. Printing with Linux
- Chapter 20. TCP/IP Network Management
- Chapter 21. Linux System Administration
- Chapter 22. Backup and Restore
- Chapter 23. System Security
- IV. Red Hat Development and Productivity
- Chapter 24. Linux C/C++ Programming Tools
- Chapter 25. Shell Scripting
- Chapter 26. Automating Tasks
- Chapter 27. Configuring and Building Kernels
- Chapter 28. Emulators, Tools, and Window Clients
- V. Appendixes
- A. The Linux Documentation Project
- B. Top Linux Commands and Utilities
- C. The GNU General Public License
- D. Red Hat Linux RPM Package Listings
Virtual Hosting
One of the more popular services to provide with a Web server is to host a virtual domain, also known as a virtual host. This is a complete Web site with its own domain name, as if it were a standalone machine, but it's hosted on the same machine as other Web sites. Apache implements this capability in a simple way with directives in the httpd.conf configuration file.
A new way to dynamically host virtual servers was recently added. This is enabled using the mod_vhost_alias module. The module is primarily intended for ISPs and similar large sites that host a large number of virtual sites. This is a module for more advanced use, and as such it goes outside the scope of this introductory chapter. Instead, this section concentrates on the traditional ways of hosting virtual servers.
Address-Based Virtual Hosts
Once you have configured your Linux machine with multiple IP addresses, setting up Apache to serve them as different Web sites is quite simple. You need only put a VirtualHost directive in your httpd.conf file for each of the addresses that you want to make an independent Web site:
<VirtualHost gnulix.org> ServerName gnulix.org DocumentRoot /home/virtual/gnulix/public_html TransferLog /home/virtual/gnulix/logs/access_log ErrorLog /home/virtual/gnulix/logs/error_log </VirtualHost>
It is recommended that you use the IP address, rather than the hostname, in the VirtualHost tag.
You may specify any configuration directives within the <VirtualHost> tags. For example, you may want to set AllowOverrides directives differently for virtual hosts than you do for your main server. Any directives that are not specified default to the settings for the main server.
The directives that cannot be set in VirtualHost sections are ServerType, StartServers, MaxSpareServers, MinSpareServers, MaxRequestsPerChild, BindAddress, Listen, PidFile, TypesConfig, ServerRoot, and NameVirtualHost.
Name-Based Virtual Hosts
Name-based virtual hosts allow you to run more than one host on the same IP address. You need to add the additional names to your DNS as CNAMEs of the machine in question. When an HTTP client (Web browser) requests a document from your server, it sends with the request a variable indicating the server name from which it is requesting the document. Based on this variable, the server determines from which of the virtual hosts it should serve content.
Name-based virtual hosts require just one step more than IP address-based virtual hosts. You first need to indicate which IP address has the multiple DNS names on it. This is done with the NameVirtualHost directive:
NameVirtualHost 212.85.67.67
You then need to have a section for each name on that address, setting the configuration for that name. As with IP-based virtual hosts, you only need to set those configurations that need to be different for the host. You must set the ServerName directive because that is the only thing that distinguishes one host from another:
<VirtualHost 212.85.67.67> ServerName bugserver.gnulix.org ServerAlias bugserver DocumentRoot /home/bugserver/htdocs ScriptAlias /home/bugserver/cgi-bin TransferLog /home/bugserver/logs/access_log </VirtualHost> <VirtualHost 212.85.67.67> ServerName pts.gnulix.org ServerAlias pts DocumentRoot /home/pts/htdocs ScriptAlias /home/pts/cgi-bin TransferLot /home/pts/logs/access_log ErrorLog /home/pts/logs/error_log </VirtualHost>
Logging | Next Section

Account Sign In
View your cart