About Linux FAQ

Browse More FAQs:

Apache name based VirtualHost example

Posted by Vivek Gite [Last updated: October 27, 2006]

Q. Can you give or specify an example for Apache name based VirtualHost feature?

A. The term Virtual Host refers to the practice of maintaining more than one web site on one Apache machine or server.

The NameVirtualHost directive is a required directive if you want to configure name-based virtual hosts.

With the NameVirtualHost directive you specify the IP address on which the server will receive requests for the name-based virtual hosts. This will usually be the address to which your name-based virtual host names resolve.

For example if your IP address is 203.54.2.5. Set it as follows in httpd.conf file:
# vi /etc/httpd/conf/httpd.conf
Set NameVirtualHost as follows:
NameVirtualHost 203.54.2.5:80
Let us see how your virtual host entry looks for two domains called theos.in and nixcraft.com . Code for theos.in domain:
<VirtualHost theos.in/>
ServerAdmin webmaster@theos.in
DocumentRoot /var/www/theos.in
ServerName theos.in
ServerAlias www.theos.in
ErrorLog /var/logs/httpd/theos.in/error_log
CustomLog /var/logs/httpd/theos.in/access_log common
</VirtualHost>

Code for nixcraft.com domain:
<VirtualHost nixcraft.com/>
ServerAdmin webmaster@nixcraft.com
DocumentRoot /var/www/nixcraft.com
ServerName nixcraft.com
ServerAlias www.nixcraft.com
ErrorLog /var/logs/httpd/nixcraft.com/error_log
CustomLog /var/logs/httpd/nixcraft.com/access_log common
</VirtualHost>

Save and close the file. Restart Apache:
# /etc/init.d/httpd restart

Make sure both domains theos.in and nixcraft.com points to (A address) 203.54.2.5. Also make sure you create /var/logs/httpd/domain-name directories and point ftp user directory to appropriate /var/www/domain-name directory.

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Other Helpful FAQs:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.