Tuesday, November 22, 2011

Tips 13: Apache VirtualHosts

Apache, the popular Web server for Linux and Unix, allows you to domain virtual domainnames with multiple IP addresses. You can set one IP to each domainname. But what if you want to domain multiple domainnames on a single IP? Apache allows you to do it.

The trick is a single command that goes in the httpd.conf configuration file:
NameVirtualdomain 1.2.3.4

Replacing 1.2.3.4 with your real IP address, this will allow Apache to know on which IP it should serve the
virtual domainnames. Then you can add the virtual commands for every domainname you want to domain:

<Virtualdomain virtual.domain.com>
ServerAdmin webmaster@virtual.domain.com
DocumentRoot /home/httpd/virtual
ServerName virtual.domain.com
</Virtualdomain>

This will add virtual.domain.com in your list of virtual domains and serve the pages in /home/httpd/virtual. Of
course you need to have the actual virtual.domain.com domainname pointing to that system.

No comments:

Post a Comment