Tuesday, October 14, 2008

How to set up virtual servers in apache2 (using Ubuntu Intrepid)

Assuming you have apache2 installed.

Go to /etc/apache2/apache2.conf

Open it with your favorite text editor and at the very end add:

NameVirtualHost 192.168.1.102


DocumentRoot /var/www/website1
ServerName website1.com
ServerAlias www.website1.com



DocumentRoot /var/www/website2
ServerName website2.com
ServerAlias www.website2.com


Ok now lets analyze what we just did.

This is the static IP address on my LAN. Whatever you pick you must open port 80 to redirect to this static IP address.

DocumentRoot /var/www/ben/website1 This is where I keep the material for my first website.

ServerName website1.com
ServerAlias www.website1.com

This will allow website1.com AND www.website1.com to work on the webserver, otherwise website1.com might return a site not found (401) error.

Close my virtual site.

You can have as many of these as you like as long as you don't exceed RAM, bandwidth, etc...

No comments: