Wednesday, March 23, 2011

VirtualHost Examples: IP-based virtual hosting

This document attempts to answer the commonly-asked questions about setting up virtual hosts.

These scenarios are those involving multiple web sites running on a single server, via name-based or IP-based virtual hosts.

The server has two IP addresses (172.20.30.40 and 172.20.30.50) which resolve to the names http://www.example1.com/ and http://www.example2.org/ respectively.
##############################################
Server configuration

Listen 80

<VirtualHost 172.20.30.40>
DocumentRoot /www/example1
ServerName http://www.example1.com/
</VirtualHost>

<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName http://www.example2.org/
</VirtualHost>
###############################################

Requests for any address not specified in one of the <VirtualHost> directives (such as localhost, for example) will go to the main server, if there is one.

1 comment:

  1. Hosting companies provide this service by maintaining a large server and on that large server they maintain a number of virtual web hosts. website hosting services india

    ReplyDelete