Home arrow Apache arrow Page 3 - Configuring and Using Virtual Hosts in Apache

Virtual Host - Apache

Begin creating and managing virtual hosts with Apache with this clear explanation from Dan Wellman. He explains what virtual hosts are and illustrates a basic way of setting up virtual hosts.

  1. Configuring and Using Virtual Hosts in Apache
  2. Edit the Main Configuration File
  3. Virtual Host
  4. Find File System Called Hosts
By: Dan Wellman
Rating: starstarstarstarstar / 107
June 30, 2004

print this article



To begin, remove the comment symbol from the start of the NameVirtualHost directive.  By default this should already be followed by *:80, this means the server will listen to any and all IP addresses on port 80 (the default port for web services). 

Next you can either add the directive <VirtualHost www.site1.co.uk> to the very bottom of the file, or remove the hash symbol and overtype the example. Remember, this needs to match the server name defined in section 2 of the configuration file.

Next, explicitly state the server name:

ServerName www.site1.co.uk 

The next line of code defines the folder that normal HTML documents are served from; add DocumentRoot "pathtoyourdocumentroot" to the next line.  The document path will typically be something like www/var/html/site1 on a UNIX platform.

Lastly, add ServerAdmin webmaster@site1.co.uk to give a contact email address on error documents and add the closing </VirtualHost> tag.

Now, you need to define the actual virtual host; copy the block of text that you have just created and paste it directly below it. Now just change the values containing site1 to site2 and ensure the document root statement matches your directory set up. Now save the file and restart Apache to update its configuration.

Simply using the technique described above will not let web users access your virtual site; in order for them to use the site URL, it will need to be included on the servers DNS record. This is relatively easy and usually requires you to simply add the virtual host name to the existing line of the DNS record for your IP address. When using IP based virtual hosts, you will need to add the IP address and the virtual server name below your existing IP address and host name.

Configuring IP based virtual hosts is usually similar although you use the IP address for your virtual host in the opening <VirtualHost> tag, for example;


Next state the site name in the ServerName directive, e.g.

ServerName www.site2.co.uk

You then add the remaining ServerAdmin etc, directives. In addition to this, in order to make Apache bind to the appropriate IP addresses and server names, you will need to add a listen directive to section 1 of the httpd.conf file. There should already be one present, so scroll up through the file until you find it and add Listen (or whatever happens to be the IP address you have been allocated.)  Once you have saved the configuration file and restarted the server, and the DNS records have been updated, this should then work.

When setting up IP based virtual hosts, you will need to have already acquired your IP addresses. These can be obtained normally from your ISP.

>>> More Apache Articles          >>> More By Dan Wellman

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Apache Unveils Cassandra 1.2
- Apache on ARM Chips? Dell and Calxeda Help M...
- The Down Side of Open Source Software
- VMware Unveils Serengeti for Apache Hadoop
- SAP Takes Steps to Improve Hadoop Integration
- Looking to Hone Apache Hadoop Skills?
- How to Install Joomla on WAMPP
- Working with XAMPP and Wordpress
- GUI Available for Apache Camel
- Reduce Server Load for Apache and PHP Websit...
- Creating a VAMP (Vista, Apache, MySQL, PHP) ...
- Putting Apache in Jail
- Containing Intrusions in Apache
- Server Limits for Apache Security
- Setting Permissions in Apache

Developer Shed Affiliates


Dev Shed Tutorial Topics: