Apache name based VirtualHost example
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:
- How do I find out syntax errors in my Apache web server configuration file?
- Why my Apache Server Side Include (SSI) is not working?
- Apache restrict access based on IP address to selected directories
- Apache Log Files
- Howto rebuild Apache for Cpanel Linux / UNIX Server (Control Panel)
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!


Recent Comments
Today ~ 32 Comments
Yesterday ~ 1 Comment
Yesterday ~ 3 Comments
Yesterday ~ 2 Comments
Yesterday ~ 3 Comments