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 www.example.com , mail.example.com , blog.example.com 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.
Open up /etc/httpd/conf/httpd.conf with your favorite text editor (I personally use joe in console).
Coment out this line:
Comment out these lines (in the VirtualHost containers and change accordingly to your server name:
CustomLog /var/log/www.example.com.common.log common
CustomLog /var/log/mail.example.com.common.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.
Restart apache by issuing "service httpd restart" in console (without the double quote). Notice any error if any.
Now you can try accessing your server with www.example.com and mail.example.com. See if it serves the right page. If yes, congratulations. You have successfully done it.
That's all there is to it. Have fun.