Sunday, December 24, 2006

Setting up name-based virtual host on apache

I just finished setting up name-based virtual host for one of my clients. The server is Red Hat Linux Enterprise 4 update 4 (RHEL) with public IP. After I have successfully setting up DNS server correctly in particular to access to this server, this is how I setup name-based virtual host for it.

What is name-based virtual host?
A feature for webserver (ie apache,IIS etc) to serve many websites with one IP. The server will serve webpages accordingly based on the name of the site (ie , , etc2).

Let's do it.
This tip is for Red Hat and maybe the same for Fedora Core (FC). On Mandriva and other distros, the directive to change may be in different files and different folders.

Step 1
Open up /etc/httpd/conf/httpd.conf with your favorite text editor (I personally use joe in console).

Step 2
Coment out this line:

NameVirtualHost *:80

Step 3
Comment out these lines (in the VirtualHost containers and change accordingly to your server name:

DocumentRoot /var/www/html/
ErrorLog /var/log/
CustomLog /var/log/ common

DocumentRoot /var/www/html/email
ErrorLog /var/log/
CustomLog /var/log/ common

See the DocumentRoot directive in each VirtualHost container. It is different. And also see the difference of ServerName directive. It is used by Apache to differentiate the website served based on the name.

Step 4
Restart apache by issuing "service httpd restart" in console (without the double quote). Notice any error if any.

Step 5
Now you can try accessing your server with and See if it serves the right page. If yes, congratulations. You have successfully done it.

That's all there is to it. Have fun.

1 comment:

satya said...

nice to see u again.... i got what i was looking for.....thnks for the post ----------------- freelancer jobs in india -----------------------