天天看點

​Linux網絡服務之HTTP(2)

linux網絡服務之http(2)

實驗要求:

1、部署基于域名的虛拟主機,當使用者通路www.baidu.com的時候通路baidu網站,當使用者通路www.sina.com的時候通路sina網站,baidu和sina的ip位址一樣,確定前述www.zhy.com通路還能通路

2、部署基于ip的虛拟主機

www.zhy.com192.168.1.253

www.baidu.com192.168.1.12

www.google.com192.168.1.11

實驗步驟:

(1)基于域名的虛拟主機

1、安裝軟體包

略……

配置dns解析

[root@server ~]# cat /var/named/chroot/etc/named.rfc1912.zones

……

zone "com" in {

       type master;

       file "zhy.com.zone";

[root@server ~]# cat /var/named/chroot/var/named/zhy.com.zone

$ttl    86400

@       in      soa     zhy.com. root.zhy.com.  (

                                     2014050201 ; serial

                                     28800      ; refresh

                                     14400      ; retry

                                     3600000    ; expire

                                     86400 )    ; minimum

               in      ns      com.

dns1.zhy        in      a       192.168.1.253

www.zhy         in      a       192.168.1.253

bbs.zhy         in      a       192.168.1.251

www.baidu       in      a       192.168.1.253

www.sina        in      a       192.168.1.253

修改配置檔案

[root@server ~]# cat /etc/httpd/conf.d/virt.conf //虛拟主機配置檔案

namevirtualhost 192.168.1.253

<virtualhost 192.168.1.253>

   documentroot /var/www/html/

   servername www.zhy.com

   errorlog logs/zhy.com-error_log

   customlog logs/zhy.com-access_log common

</virtualhost>

   documentroot /web/sina/

   servername www.sina.com

   errorlog logs/sina.com-error_log

   customlog logs/sina.com-access_log common

   documentroot /web/baidu/

   servername www.baidu.com

   errorlog logs/baidu.com-error_log

   customlog logs/baidu.com-access_log common

[root@server ~]# cat /web/sina/index.html //建立測試站點

this is sina.com!!!

[root@server ~]# cat /web/baidu/index.html

this is baidu.com!!!

(2)基于ip位址的虛拟主機

配置dns實作解析

               in       ns      com.

dns1.zhyin       a       192.168.1.253

www.zhyin       a       192.168.1.253

bbs.zhy          in       a       192.168.1.251

www.baidu       in      a       192.168.1.12

www.sina        in      a       192.168.1.11

1、配置虛拟網卡,實作多個ip位址共存

[root@server ~]# cd /etc/sysconfig/network-scripts/

[root@server network-scripts]# cp -p ifcfg-eth0 ifcfg-eth0:0

[root@server network-scripts]# cp -p ifcfg-eth0 ifcfg-eth0:1

[root@server network-scripts]# cat ifcfg-eth0:0

# intel corporation 82545em gigabit ethernet controller (copper)

device=eth0:0

bootproto=static

onboot=yes

ipaddr=192.168.1.11

netmask=255.255.255.0

[root@server network-scripts]# cat ifcfg-eth0:1

device=eth0:1

ipaddr=192.168.1.12

2、修改虛拟主機配置檔案

[root@server ~]# cat /etc/httpd/conf.d/virt.conf

<virtualhost 192.168.1.253:80>

<virtualhost 192.168.1.11:80>

<virtualhost 192.168.1.12:80>

啟動服務,設定服務開機自啟

[root@server ~]#service httpd restart

[root@server named]# service network restart

正在關閉接口 eth0:                                        [确定]

關閉環回接口:                                             [确定]

彈出環回接口:                                             [确定]

彈出界面 eth0:                                            [确定]

[root@server named]# ifconfig

eth0      link encap:ethernet  hwaddr 00:0c:29:63:58:fe  

         inet addr:192.168.1.253  bcast:192.168.1.255  mask:255.255.255.0

eth0:0    link encap:ethernet  hwaddr 00:0c:29:63:58:fe  

         inet addr:192.168.1.11  bcast:192.168.1.255  mask:255.255.255.0

eth0:1    link encap:ethernet  hwaddr 00:0c:29:63:58:fe  

         inet addr:192.168.1.12  bcast:192.168.1.255  mask:255.255.255.0

[root@server ~]#chkconfig httpd on

[root@server ~]#chkconfig network on

[root@server ~]#chkconfig named on

測試

注意:測試前需要清理一下浏覽器的緩存,以防緩存導緻實驗測試失敗!!

本文出自 “” 部落格,請務必保留此出處