Red Hat Linux 7 Unleashed

Red Hat Linux 7 Unleashed

By William Ball

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>
					
					
					
				

Share ThisShare This

Informit Network