Virtual Host Support

What are virtual hosts?

This is the ability of a single machine to be a web server for multiple domains. For example, an internet service provider might have a machine called www.serve.com which provides Web space for several organisations including, say, smallco and baygroup. Ordinarily, these groups would be given parts of the Web tree on www.serve.com. So smallco's home page would have the URL
http://www.serve.com/smallco/
and baygroup's home page would have the URL
http://www.serve.com/baygroup/

For aesthetic reasons, however, both organisations would rather their home pages appeared under their own names rather than that of the service provider's; but they do not want to set up their own internet links and servers.

Virtual hosts are the solution to this problem. smallco and baygroup would have their own internet name registrations, www.smallco.com and www.baygroup.org respectively. These hostnames would both correspond to the service provider's machine (www.serve.com). Thus smallco's home page would now have the URL

http://www.smallco.com/
and baygroup's home page would would have the URL
http://www.baygroup.org/

System requirements

Due to limitations in the HTTP/1.0 protocol, the web server must have a different IP address for each virtual host. This can be achieved by the machine having several physical network connections, or by use of a virtual interface on some operating systems.

How to set up Apache

There are two ways of configuring apache to support multiple hosts. Either by running a separate httpd daemon for each hostname, or by running a single daemon which supports all the virtual hosts.

Use multiple daemons when:

Use a single daemon when:

Setting up multiple daemons

Create a separate httpd installation for each virtual host. For each installation, use the BindAddress option in the httpd.conf configuration file to select which IP address (or virtual host) that daemon services. e.g.
BindAddress www.smallco.com
This hostname can also be given as an IP address.

Setting up a single daemon

For this case, a single httpd will service requests for all the virtual hosts. The VirtualHost option in the httpd.conf configuration file is used to set the values of ServerAdmin, ServerName, DocumentRoot, ErrorLog and TransferLog configuration options to different values for each virtaul host. e.g.
<VirtualHost www.smallco.com>
ServerAdmin webmaster@mail.smallco.com
DocumentRoot /groups/smallco/www
ServerName www.smallco.com
ErrorLog /groups/smallco/logs/error_log
TransferLog /groups/smallco/logs/access_log
</VirtualHost>

<VirtualHost www.baygroup.org>
ServerAdmin webmaster@mail.baygroup.org
DocumentRoot /groups/baygroup/www
ServerName www.baygroup.org
ErrorLog /groups/baygroup/logs/error_log
TransferLog /groups/baygroup/logs/access_log
</VirtualHost>
This VirtualHost hostnames can also be given as IP addresses.


Home Index