Different types of Apache virtual-host implementation
Running several name-based web sites on a single IP address.
[root@www ~]# hostname
[root@www ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:FD:20:1A
inet addr:172.16.28.175 Bcast:172.16.28.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fefd:201a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:61 errors:0 dropped:0 overruns:0 frame:0
TX packets:54 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9213 (8.9 KiB) TX bytes:8449 (8.2 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:576 (576.0 b) TX bytes:576 (576.0 b)
[root@www ~]# rpm -qa httpd
httpd-2.2.15-45.el6.centos.x86_64
[root@www ~]# rpm -qi httpd
Name : httpd Relocations: (not relocatable)
Version : 2.2.15 Vendor: CentOS
Release : 45.el6.centos Build Date: Friday 24 July 2015 04:53:33 AM PDT
Install Date: Tuesday 26 April 2016 06:59:42 AM PDT Build Host: c6b9.bsys.dev.centos.org
Group : System Environment/Daemons Source RPM: httpd-2.2.15-45.el6.centos.src.rpm
Size : 3090869 License: ASL 2.0
Signature : RSA/SHA1, Friday 24 July 2015 01:42:58 PM PDT, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem <http://bugs.centos.org>
URL : http://httpd.apache.org/
Summary : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.
[root@www ~]# date
Sat May 28 19:06:52 PDT 2016
May be package version has been updated so we shall go for new updated package
[root@www ~]# yum list installed | grep httpd
httpd.x86_64 2.2.15-45.el6.centos
httpd-tools.x86_64 2.2.15-45.el6.centos
[root@www ~]# yum install httpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.vinahost.vn
* extras: mirrors.vinahost.vn
* updates: mirrors.vinahost.vn
Resolving Dependencies
–> Running transaction check
—> Package httpd.x86_64 0:2.2.15-45.el6.centos will be updated
—> Package httpd.x86_64 0:2.2.15-53.el6.centos will be an update
–> Processing Dependency: httpd-tools = 2.2.15-53.el6.centos for package: httpd-2.2.15-53.el6.centos.x86_64
–> Running transaction check
—> Package httpd-tools.x86_64 0:2.2.15-45.el6.centos will be updated
—> Package httpd-tools.x86_64 0:2.2.15-53.el6.centos will be an update
–> Finished Dependency Resolution
Complete!
[root@www ~]# yum list installed | grep httpd
httpd.x86_64 2.2.15-53.el6.centos
httpd-tools.x86_64 2.2.15-53.el6.centos
[root@www ~]# service httpd status
httpd is stopped
[root@www ~]# chkconfig –list | grep httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@www ~]# netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2182/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1991/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2316/master
tcp 0 0 :::22 :::* LISTEN 2182/sshd
tcp 0 0 ::1:631 :::* LISTEN 1991/cupsd
tcp 0 0 ::1:25 :::* LISTEN 2316/master
[root@www ~]# service httpd start
Starting httpd: [ OK ]
[root@www ~]# service httpd status
httpd (pid 2761) is running…
[root@www ~]# netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2182/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1991/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2316/master
tcp 0 0 :::80 :::* LISTEN 2761/httpd
tcp 0 0 :::22 :::* LISTEN 2182/sshd
tcp 0 0 ::1:631 :::* LISTEN 1991/cupsd
tcp 0 0 ::1:25 :::* LISTEN 2316/master
[root@www ~]# chkconfig httpd on
[root@www ~]# chkconfig –list | grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@www ~]# httpd -t
Syntax OK
/etc/httpd/conf/httpd.conf (Main Configuration File)
[root@www ~]# vim /etc/httpd/conf/httpd.conf
Note:By default port is in Listen state in line number 139 og configuration file
136 Listen 80
I am adding below content at the end of configuration file
[root@www ~]# vim /etc/httpd/conf/httpd.conf
Listen 80
<VirtualHost *:80>
DocumentRoot “/var/www/linuxmadeeasy”
directoryindex firstsite.html
ServerName http://www.linuxmadeeasy.in
</VirtualHost>
[root@www ~]# httpd -t
Warning: DocumentRoot [/var/www/linuxmadeeasy/firstsite.html] does not exist
Syntax OK
[root@www ~]# mkdir /var/www/linuxmadeeasy
[root@www ~]# cd /var/www/linuxmadeeasy/
[root@www linuxmadeeasy]# touch firstsite.html
I am placing this html content into it
[root@www linuxmadeeasy]# vim firstsite.html
[root@www linuxmadeeasy]# cat firstsite.html
<head>
<body>
this is the content in my first web page
</body>
</head
[root@www linuxmadeeasy]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
Note:Using /etc/hosts file as local DNS for name resolution
[root@www linuxmadeeasy]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.28.175 http://www.linuxmadeeasy.in
you can use elinks as a tool for cross check from command line
[root@www ~]# yum install elinks
[root@www ~]# elinks http://www.linuxmadeeasy.in
open browser and check by typing server name you created
——————————————————————————————————————–
With same document root but different server name(Name Based)
[root@www ~]# vim /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
DocumentRoot “/var/www/linuxmadeeasy”
directoryindex firstsite.html
ServerName http://www.linuxmadeeasy.org
</VirtualHost>
[root@www ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [Sat May 28 19:55:28 2016] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[ OK ]
[root@www ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.28.175 http://www.linuxmadeeasy.in
172.16.28.175 http://www.linuxmadeeasy.org
——————————————————————————————————————–
Port Based Virtual-Hosting
[root@www ~]# cd /var/www/linuxmadeeasy/
[root@www linuxmadeeasy]# ls -l
total 4
-rw-r–r– 1 root root 70 May 28 18:47 firstsite.html
[root@www linuxmadeeasy]# touch secondsite.html
Adding this content here
[root@www linuxmadeeasy]#vim secondsite.html
<head>
<body>
this is the content in my second web page
</body>
</head
[root@www ~]# vim /etc/httpd/conf/httpd.conf
Listen 80
<VirtualHost *:80>
DocumentRoot “/var/www/linuxmadeeasy”
directoryindex secondsite.html
ServerName http://www.linuxmadeeasy.in
</VirtualHost>
[root@www ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [Sat May 28 19:18:25 2016] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
(98)Address already in use: make_sock: could not bind to address [::]:80
[ OK ]
So i did modifications for changing port
as fallows to port 8080
[root@www ~]# vim /etc/httpd/conf/httpd.conf
Listen 8080
<VirtualHost *:8080>
DocumentRoot “/var/www/linuxmadeeasy”
directoryindex secondsite.html
ServerName http://www.linuxmadeeasy.in
</VirtualHost>
[root@www ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@www ~]# netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2182/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1991/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2316/master
tcp 0 0 :::8080 :::* LISTEN 3533/httpd
tcp 0 0 :::80 :::* LISTEN 3533/httpd
tcp 0 0 :::22 :::* LISTEN 2182/sshd
tcp 0 0 ::1:631 :::* LISTEN 1991/cupsd
tcp 0 0 ::1:25 :::* LISTEN 2316/master
————————————————————————————————————————–
IP Based Hosting
[root@www ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:FD:20:1A
inet addr:172.16.28.175 Bcast:172.16.28.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fefd:201a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:32838 errors:0 dropped:0 overruns:0 frame:0
TX packets:20930 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:29291357 (27.9 MiB) TX bytes:2216556 (2.1 MiB)
Since we have only one interface add another interface
[root@www ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:FD:20:1A
inet addr:172.16.28.175 Bcast:172.16.28.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fefd:201a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:32876 errors:0 dropped:0 overruns:0 frame:0
TX packets:20965 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:29302892 (27.9 MiB) TX bytes:2220365 (2.1 MiB)
eth2 Link encap:Ethernet HWaddr 00:0C:29:FD:20:24
inet addr:172.16.28.179 Bcast:172.16.28.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fefd:2024/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:20 errors:0 dropped:0 overruns:0 frame:0
TX packets:21 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2550 (2.4 KiB) TX bytes:2672 (2.6 KiB)
[root@www ~]# vim /etc/httpd/conf/httpd.conf
<VirtualHost 172.16.28.179:80>
DocumentRoot “/var/www/linuxmadeeasy”
directoryindex thirdsite.html
ServerName http://www.linuxmadeeasy.edu
</VirtualHost>
[root@www ~]# cat /var/www/linuxmadeeasy/thirdsite.html
<head>
<body>
this is the content in my third web page
</body>
</head
[root@www ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.28.175 http://www.linuxmadeeasy.in
172.16.28.175 http://www.linuxmadeeasy.org
172.16.28.179 http://www.linuxmadeeasy.edu
[root@www ~]# httpd -t
[Sat May 28 21:43:50 2016] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
Syntax OK
[root@www ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [Sat May 28 21:43:57 2016] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
With the same document root which i used for “www.linuxmadeeasy.in” i will host it with different ip address i.e on (172.16.28.179)
[root@www ~]# vim /etc/httpd/conf/httpd.conf
<VirtualHost 172.16.28.179:80>
DocumentRoot “/var/www/linuxmadeeasy”
directoryindex firstsite.html
ServerName http://www.linuxmadeeasy.in
</VirtualHost>
[root@www ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:FD:20:1A
inet addr:172.16.28.175 Bcast:172.16.28.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fefd:201a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:41711 errors:0 dropped:0 overruns:0 frame:0
TX packets:28360 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:36181145 (34.5 MiB) TX bytes:3035484 (2.8 MiB)
eth2 Link encap:Ethernet HWaddr 00:0C:29:FD:20:24
inet addr:172.16.28.179 Bcast:172.16.28.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fefd:2024/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11064 errors:0 dropped:0 overruns:0 frame:0
TX packets:2537 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1106786 (1.0 MiB) TX bytes:325117 (317.4 KiB)
[root@www ~]# ifdown eth0
[root@www ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:fd:20:1a brd ff:ff:ff:ff:ff:ff
inet6 fe80::20c:29ff:fefd:201a/64 scope link
valid_lft forever preferred_lft forever
3: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN
link/ether 1a:96:d8:16:a3:b4 brd ff:ff:ff:ff:ff:ff
6: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:fd:20:24 brd ff:ff:ff:ff:ff:ff
inet 172.16.28.179/24 brd 172.16.28.255 scope global eth2
inet6 fe80::20c:29ff:fefd:2024/64 scope link
valid_lft forever preferred_lft forever
Note:so eth0 is down and host which are running on 172.16.28.179(eth2) will only be appreared
[root@www ~]# httpd -t
[Sat May 28 22:04:26 2016] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
Syntax OK
[root@www ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [Sat May 28 22:04:32 2016] [warn] _default_ VirtualHost overlap on port 80, the first has precedence












