■虛擬Web主機
●在同一臺服務器中運行多個Web站點,其中每一一個站點並不獨立
佔用一臺真正的計算機
■httpd支持的虛擬主機類型
●基於域名的虛擬主機
●基於IP地址的虛擬主機
●基於端口的虛擬主機:html
●構建2個虛擬Web站點
www.kgc.com, IP地址爲173.17.17.11
www.kcce.com, IP地址爲173.17.17.11
●在瀏覽器中訪問這兩個域名時,分別顯示不一樣的內容vim
1.爲虛擬主機提供域名解析瀏覽器
[root@dnssvr ~]# vim /var/named/chroot/var/named/kgc.com.zone
@ IN NS dnssvr.kgc.com.
dnssvr IN A 173.1 7.1 7.2
www IN A 173.17.17.11
[root@dnssvr ~]# vim /var/named/chroot/var/named/kcce.com.zone
......
@ IN NS dnssvr.kgc.com.
www IN A 173.17.1711服務器
2.爲虛擬主機準備網頁文檔ide
[root@www ~]# mkdir -p /var/www/html/kgc
[root@www ~]# mkdir -p /var/www/html/accp
[root@www ~]# echo " <h1>www.kgc.com</h1>" >
/var/www/html/kgccom/index.html
[root@www ~]# echo
! <h1>www.accp.com</h1>" >
/var/www/html/kccecom/index.htmlui
3.添加虛擬主機配置htm
[root@www ~]# vim /usr/local/httpd/conf/extra/httpd-vhosts.comf
<VirtualHost :80>
DocumentRoot "/var/www/html/kgccom"
ServerName www.kgc.com
ErrorLog "logs/www.kgc.com.error_log"
CustomLog "logs/www.kgc.com.access_log" common
< Directory "/var/www/html" >
Require all granted
</Directory>
</VirtualHost>
<VirtualHost :80>
DocumentRoot "/var/www/html、accp
ServerName www.accp.com
ErrorLog "logs/www.accp.com.error_log"
CustomLog "logs/www.accp.com.access_log" common
< Directory "/var/www/html" >
Require all granted
</Directory>
< /VirtualHost>dns
4.在客戶機分別訪問虛擬Web主機文檔
●構建2個虛擬Web站點域名
www.kgc.com, IP地址、 端口爲173.17.17.11:80
www.accp.com, IP地址、 端口爲173.17.17.11:8353
在瀏覽器中訪問這兩個端口時,分別顯示不一樣的內容
[root@www ~]# vim /usr/loca/httpd/conf/extra/httpd-vhosts.conf
< VirtualHost 173.17.17.11:80習
DocumentRoot "/var/wwwhtml/kccecom"
ServerName www.kgc.com
</VirtualHost>
<VirtualHost 173.17.17.11:8353)
DocumentRoot "/var/www/html/kccepad"
ServerName www.accp.com
< NirtualHost>
Listen 80
Listen 8353
■應用示例:●構建2個虛擬Web站點www.kgc.com, IP地址爲220.181.120.61www.kcce.com, IP地址爲122.115.32.133在瀏覽器中訪問這兩個IP時P分別顯示不一樣的內容[root@www ~]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf< VirtualHost 220.181.120.61:80>DocumentRoot "/var/www/html/kgccom"ServerName www.kgc.com</NirtualHost> I<VirtualHost 122.115.32.133:80>DocumentRoot "/var/www/htm/kccecom"ServerName www.kcce.com</VirtualHost>