Sunday, October 31, 2010

Basic Local Name Based Virtual Hosting

Name based virtual hosting - shared IP - multiple hostnames on a single machine with a single IP address. The hostname is part of the request to the server. The server uses this information to determine which web site to show the user. This may fail if the user directly types the IP address directly to reach a webhost.

-create mysite.local.conf in /etc/apache2/sites-available

-(add the below to mysite.local.conf)


<virtualhost *:80>
ServerName mysite.local
DocumentRoot /home/user/www/mysite.local
</VirtualHost>


(apache actually looks for virtual hosts in /etc/apache2/sites-enabled. So create a symbolic link from here to mysite.local.conf with the same name)

sudo ln -s /etc/apache2/sites-available/mysite.local.conf mysite.local.conf

(add to /etc/hosts)
127.0.0.1 mysite.local

So now ,
http://example.local gets to page at /var/www
http://mysite.local gets to page at /home/user/www/mysite.local