From the Apache 2.0 documentation:
The term Virtual Host refers to the practice of running more than one web site (such as www.company1.com and www.company2.com) on a single machine. Virtual hosts can be "IP-based", meaning that you have a different IP address for every web site, or "name-based", meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user.
Since most of our customers are running systems with only a single IP address we'll be dealing only with the configuring name based virtual hosts.
This document outlines how to host multiple web sites using an HTTPd server, a single dynamic IP address, and multiple hostnames in our Dynamic DNS or Custom DNS services. Specific info is being provided for Apache 1.3 and Apache 2.0.
Specific help with the installation of Apache is outside the scope of this document, please consult the accompanying documentation with your Apache distribution for assistance.
Open the file httpd.conf in your favorite text editor. On Unix systems, this file can usually be found in one of
/etc/httpd/ /usr/local/etc/httpd/ /usr/local/apache/conf
On Windows systems, this file can typically be found in
C:\Program Files\Apache Group\Apache\conf
Apache 1.3 only: The first thing to look for is the line that says:
#BindAddress *
You should uncomment this line (remove the # at the beginning), so that it reads:
BindAddress *
Note: The BindAddress directive has been removed in Apache 2.0 along with the Port directive. The Listen directive is now used for this purpose.
Next, locate and uncomment the line that says:
Listen 80
Note: In this configuration Apache will listen on all bound IP addresses. The is the default desired behavior when running Apache in an environment where the IP address is dynamic and/or you have only a single network interface.
Note also: If you are forced to use an alternate port because your ISP blocks port 80, this is where you define that alternate port in Apache.
We now have to set up the actual Virtual Hosts. Locate the line that says:
#NameVirtualHost *
Uncomment this line so that it reads:
NameVirtualHost *
This will enable name-based Virtual Hosts.
<VirtualHost *> ServerName test1.dyndns.org DocumentRoot /path/to/test1/files </VirtualHost>
<VirtualHost *> ServerName test2.dyndns.org DocumentRoot /path/to/test2/files </VirtualHost>
Optionally, you can also add the line:
ServerAlias *.test1.dyndns.org
beneath the ServerName line - this is for users using the wildcard feature.
Read more. Further reading on virtual hosts in Apache can be found in the Apache 2.0 documentation. Of particular usefulness is page which provides examples of different kinds of virtual host setups. While most customers won't need more than the above, reviewing this page from the Apache docs may give you a important insights into how virtual hosts work.