One great benefit of VPS hosting is being able to easily host multiple websites off the same server. Owning a VPS offers much more than just web hosting but in this tutorial we will show you how to setup virtual hosts with Apache.

Apache HTTP Server is probably one of the most influential pieces of open-source software that let to the explosive growth of the World Wide Web today. Still going strong it is the leading web server used across the internet today. Apache HTTP Server runs on many operating systems such as Unix, Linux, BSD, Windows, OSX, and Solaris, among others.

Apache HTTP Server is developed by the Apache Software Foundation, and has a strong community of  developers supporting the project.

Apache Virtual Hosts Configuration

Setting up virtual hosts is straightforward. In your HTTP Configuration file add the following lines. Modify the settings for your environment. .

Shared IP with Multiple Virtual Hosts

# accept virtual host requests on all IP's
NameVirtualHost *:80
 
<VirtualHost *:80>
DocumentRoot /www/domain1
ServerName www.domain1.com
 
</VirtualHost>
 
<VirtualHost *:80>
DocumentRoot /www/domain2
ServerName www.domain2.net
 
</VirtualHost>
 

Virtual Hosts with dedicated IP addresses

 

Listen 80
 
# This is the server running on your main IP.
ServerName server.maindomain.com
DocumentRoot /www/maindomain
 
# Virtual Servers will use other IP address
NameVirtualHost 123.231.199.50
 
<VirtualHost 123.231.199.50>
DocumentRoot /www/domain1
ServerName www.domain.com
 
</VirtualHost>
 
<VirtualHost 123.231.199.50>
DocumentRoot /www/domain2
ServerName www.domain2.net
 
</VirtualHost>

Combination Name Based and IP Based Apache Virtual Hosts

Listen 80
 
NameVirtualHost 123.231.199.50
 
<VirtualHost 123.231.199.50>
DocumentRoot /www/domain1
ServerName www.domain.com
</VirtualHost>
 
<VirtualHost 123.231.199.50>
DocumentRoot /www/domain2
ServerName www.domain2.org
</VirtualHost>
 
<VirtualHost 123.231.199.50>
DocumentRoot /www/domain3
ServerName www.domain3.com
</VirtualHost>
 
## - IP Based Hosted Domains
<VirtualHost 123.231.199.51>
DocumentRoot /www/domain4
ServerName www.domain4.info
</VirtualHost>
 
<VirtualHost 123.231.199.51>
DocumentRoot /www/domain5
ServerName www.domain5.me
</VirtualHost>