APACHE VIRTUAL HOSTING
Virtual
Hosting
Named Based Virtual Hosting
IP Based Virtual Hosting
Named Based Virtual Hosting
1. One IP and many Website.
2. To enable “Named Based
Virtual Hosting” uncomment the “NameVirtualHost” tag in configuration
file.
Practical
<SERVER>
Add 2 Virtual Host (VH), and
check the configuration. Also stop the iptables service.
# vim /etc/httpd/conf/httpd.conf
<VirtualHost
*:80>
ServerAdmin
webmaster@dummy-host.example.com
DocumentRoot
/opt/website_directory1
ServerName
first.com
DirectoryIndex
index.html
ErrorLog
logs/dummy-host.example.com-error_log
CustomLog
logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost
*:80>
ServerAdmin
webmaster@dummy-host.example.com
DocumentRoot
/opt/ website_directory2
ServerName
second.com
DirectoryIndex
index.html
ErrorLog
logs/dummy-host.example.com-error_log
CustomLog
logs/dummy-host.example.com-access_log common
</VirtualHost>
:wq
2) # mkdir /opt/
website_directory1 && cd /opt/ website_directory1
3) # vim index.html
This
is first website.
:wq!
4) # mkdir /opt/
website_directory2 && cd /opt/ website_directory2
5) # vim index.html
This
is second website.
:wq
6) # /etc/init.d/iptables stop
7) Disable SELINUX
#
vim /etc/selinux/config
8) # /etc/init.d/httpd reload
<CLIENT>
1) Make entry in “/etc/hosts”
#
vim /etc/hosts
<server_ip> first.com
<server_ip> second.com
2) Check website via Browser or
“elinks” command.
#
elinks http://first.com
#
elinks http://second.com
IP Based Virtual Hosting
1. One IP and One website
2. To enable “Named Based
Virtual Hosting” comment the “NameVirtualHost” tag in configuration file.
Practical
<SERVER>
1) IP ALISING
·
#
ifconfig eth0:0 192.168.0.103 netmask 255.255.255.0
·
Copy
the “ifcfg-eth0” file and make necessary changes in it.
2) Comment the
“NameVirtualHost” directive.
3) Go to “Listen” Directive and
comment that line also adds following line:
Listen
<NIC_1-IP>:80 i.e. Listen 192.168.0.102:80
Listen
<NIC_2-IP>:80 i.e. Listen 192.168.0.103:8000 [Here I am changing
port]
4) In VH (Virtual Host),
Instead of “*” give NIC_1 & NIC_2 IP address in respective VH.
# vim /etc/httpd/conf/httpd.conf
<VirtualHost 192.168.0.102:80>
ServerAdmin
webmaster@dummy-host.example.com
DocumentRoot
/opt/website_directory1
ServerName
first.com
DirectoryIndex
index.html
ErrorLog
logs/dummy-host.example.com-error_log
CustomLog
logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost 192.168.0.103:8000> [Here
also I am changing port]
ServerAdmin
webmaster@dummy-host.example.com
DocumentRoot
/opt/ website_directory2
ServerName
second.com
DirectoryIndex
index.html
ErrorLog
logs/dummy-host.example.com-error_log
CustomLog
logs/dummy-host.example.com-access_log common
</VirtualHost>
<CLIENT>
1) Make entry in “/etc/hosts”:
#
vim /etc/hosts
<NIC_1-ip> first.com
<NIC_2-ip> second.com
2) Check website via Browser or
“elinks” command.
#
elinks http://first.com
#
elinks http://second.com:8000 [How to call website from
client with port]
Comments
Post a Comment