Virtual Hosting Example for apache

Name based virtualhost Configuration

For example if your IP address is 124.153.95.77 Set it as follows in httpd.conf file:


# vi /etc/httpd/conf/httpd.conf


Set NameVirtualHost as follows:


NameVirtualHost 124.153.95.77:80
Let us see how your virtual host entry looks for two domains called nitish.info and sis4u.com 


<VirtualHost nitish.info/>
ServerAdmin contact@nitish.info
DocumentRoot /var/www/nitish.info
ServerName nitish.info
ServerAlias www.nitish.info
ErrorLog /var/logs/httpd/nitish.info/error_log
CustomLog /var/logs/httpd/nitish.info/access_log common
</VirtualHost>


Code for sis4u.com domain:


<VirtualHost sis4u.com/>
ServerAdmin webmaster@sis4u.com
DocumentRoot /var/www/sis4u.com
ServerName sis4u.com
ServerAlias www.sis4u.com
ErrorLog /var/logs/httpd/sis4u.com/error_log
CustomLog /var/logs/httpd/sis4u.com/access_log common
</VirtualHost>


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