Network: Apache: virtual hosts

(last edit: 2001-04-15)

Setting up Apache Virtual hosts

You have several (sub)domains pointing to the same ip address but you want to treat this (sub)domains as full-features domains as if they had their own ipaddress. Well this is how to: In your httpd.conf file you'll find a line 'DocumentRoot' followed by a path. This is the setup for apache to server one domain. I'll show you how to change this into several domains. Place the following code somewhere in 'httpd.conf': --- ServerName www.example.org NameVirtualHost 212.238.1.123 <VirtualHost 212.238.1.123> ServerName www.example.org ServerAlias example.org DocumentRoot /usr/share/data/www/ </VirtualHost> <VirtualHost 212.238.1.123> ServerName my.example.org ServerAdmin admin@my.example.org DirectoryAlias /cgi-bin/ /usr/share/cgi-bin/my/ DocumentRoot /usr/share/data/my/ DirectoryIndex index.html index.htm index.php index.php3 </VirtualHost> --- The above is just an example to get you started. The 'original' lines like 'DocumentRoot' get obsolete when you have specified something like above and it is therefore neat to remove those lines. I've specified a few examples above like 'ServerAlias' and 'DocumentRoot' but almost any configuration directive can be used in the 'VirtualHost' directive. Don't forget to do a 'killall -HUP httpd' to activate the changes you've made. See also the apache Virtual Host page.

Click here to go back to the index.