Personal tools
Home Webmaster Resources Apache Virtual Hosts

Virtual Hosts

If you have a server with only one IP address, but need to serve more than one website, you can use Virtual Hosts to make that possible.

First, use the NameVirtualHost directive to specify that the virtual hosts run on all IP addresses, including localhost.

NameVirtualHost *

Then, proceed to define each of your virtual hosts as follows:

<VirtualHost *>
  ServerName www.example.com
  ServerAlias example.com dev.example.com
  DocumentRoot /var/www/html/example_com
</VirtualHost>   


ServerName and ServerAlias specify the names which associated with this virtual host.  For instance, a web user can get to http://www.example.com using http://example.com or http://dev.example.com.  However, these names must be added to your DNS server in order for them to resolve to your IP address.


The DocumentRoot directive simply tells Apache where on the server your web files are located for this site.

Need assistance with your project? Universal Web Services can help.
Contact us to request a quote.