Configure Apache Virtual Hosts on a VPS

Apache Virtual HostsOne 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. If you have any question leave a comment and we will get back to you.

Shared IP with Multiple Virtual Hosts

[code]

# 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>

[/code]

Virtual Hosts with dedicated IP addresses

[code]

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>

[/code]

Combination Name Based and IP Based Apache Virtual Hosts

[code]

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>

[/code]

Happy Hosting!
– Tutor


Posted

in

, , ,

by

Tags:

Comments

2 responses to “Configure Apache Virtual Hosts on a VPS”

  1. santosh Avatar

    Hi
    I am using WHM on my server will you tell me how to access my folder using ip address like this xx.xxx.xx.xx/myfoldername
    right now if i type my ip address it leads to my one of hosted website

    1. VPS Tutor Avatar

      To browse the subfolder from the main ip simply do this: http://IP.IP.IP.IP/~username .

Leave a Reply

Your email address will not be published. Required fields are marked *