Apache Virtual Hosting Configuration How To Configure Apache Virtual Host

Host based virtual hosting: system1: setup apache virtual host
Step 1: add host the entries in dns
#cat>>/var/named/chroot/var/named/rhel5.com.db
www IN CNAME system1.rhel5.com
mail IN CNAME system1.rhel5.com
<control+d>
reload the dns entries
#rndc reload
Step 2:Install http packages
#yum install httpd
Step 3:Create html files
#vim /var/www/html/main.html
<html>
<head><title>Sample Web Page</title></head>
<body><font size=”40” color=”FF0000”>
<marquee>This is Home Page of Rhel5.com</marquee>
</font></body></html>
#mkdir /var/www/mail
#vim /var/www/mail/mail.html
<html>
<head><title>Sample Web Page</title></head>
<body><font size=”40” color=”00FF00”>
<marquee>Welcome Mail Page of Rhel5.com</marquee>
</font></body></html>
Step 4:Add html page to http configuration file
#vim /etc/httpd/conf/httpd.conf
Line no: 390
Directory Index mail.html main.html index.html index.html.var
Line no: 998 or Last
NameVirtualHost 192.168.0.10:80
<VirtualHost 192.168.0.10:80>
Servername www.rhel5.com.
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost 192.168.0.10:80>
Servername mail.rhel5.com.
DocumentRoot /var/www/mail
</VirtualHost>
Step 5:restart the http service
#service httpd restart
sys1:
add dns entries in /etc/resolv.conf
#vim /etc/resolv.conf
search rhel5.com
nameserver 192.168.0.10
Step 6:open firefox and type the following url in address bar
http://www.rhel5.com
http://mail.rhel5.com
IP based virtual hosting:system1:
Step 1:
create ethernet alias ip address is 10.0.0.10
#netconfig ­d eth0:1
#service network restart
add host the entries in dns
#cat>>/var/named/chroot/var/named/rhel5.com.db
songs IN A 10.0.0.10
<control+d>
reload the dns entries
#rndc reload
Step 2:Install http packages
#yum install httpd
Step 3:Create html files
#mkdir /var/www/songs
#vim /var/www/mail/songs.html
<html>
<head><title>Sample Web Page</title></head>
<body><font size=”40” color=”0000FF”>
<marquee>Welcome to Songs Page of Rhel5.com</marquee>
</font></body></html>
Step 4:
Add html page to http configuration file
#vim /etc/httpd/conf/httpd.conf
Line no: 390
Directory Index songs.html mail.html main.html index.html
Line no: 998 or Last
NameVirtualHost 192.168.0.10:80
<VirtualHost 192.168.0.10:80>
Servername www.rhel5.com.
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost 192.168.0.10:80>
Servername mail.rhel5.com.
DocumentRoot /var/www/mail
</VirtualHost>
NameVirtualHost 10.0.0.10:80
<VirtualHost 10.0.0.10:80>
Servername songs.rhel5.com.
DocumentRoot /var/www/songs
</VirtualHost>
Step 5:
restart the http service
#service httpd restart
sys1:
add dns entries in /etc/resolv.conff
#vim /etc/resolv.conf
Step 6:
open firefox and type the following url in address bar
http://www.rhel5.com
http://mail.rhel5.com
http://songs.rhel5.com
Finally apache virtual host configure successfully.

Related post