新聞中心
當(dāng)服務(wù)器無法為每個(gè)網(wǎng)站都分配一個(gè)獨(dú)立IP地址的時(shí)候,可以嘗試讓Apache自動(dòng)識(shí)別用戶請(qǐng)求的域名,從而根據(jù)不同的域名請(qǐng)求來傳輸不同的內(nèi)容。在這種情況下的配置更加簡單,只需要保證位于生產(chǎn)環(huán)境中的服務(wù)器上有一個(gè)可用的IP地址(這里以192.168.10.10為例)就可以了。由于當(dāng)前還沒有介紹如何配置DNS解析服務(wù),因此需要手工定義IP地址與域名之間的對(duì)應(yīng)關(guān)系。/etc/hosts是Linux系統(tǒng)中用于強(qiáng)制把某個(gè)主機(jī)域名解析到指定IP地址的配置文件。簡單來說,只要這個(gè)文件配置正確,即使網(wǎng)卡參數(shù)中沒有DNS信息也依然能夠?qū)⒂蛎馕鰹槟硞€(gè)IP地址。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:申請(qǐng)域名、網(wǎng)絡(luò)空間、營銷軟件、網(wǎng)站建設(shè)、殷都網(wǎng)站維護(hù)、網(wǎng)站推廣。
第1步:手工定義IP地址與域名之間對(duì)應(yīng)關(guān)系的配置文件,保存并退出后會(huì)立即生效??梢酝ㄟ^分別ping這些域名來驗(yàn)證域名是否已經(jīng)成功解析為IP地址。
[root@linuxprobe ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.10 www.linuxprobe.com bbs.linuxprobe.com tech.linuxprobe.com
[root@linuxprobe ~]# ping -c 4 www.linuxprobe.com
PING www.linuxprobe.com (192.168.10.10) 56(84) bytes of data.
64 bytes from www.linuxprobe.com (192.168.10.10): icmp_seq=1 ttl=64 time=0.070 ms
64 bytes from www.linuxprobe.com (192.168.10.10): icmp_seq=2 ttl=64 time=0.077 ms
64 bytes from www.linuxprobe.com (192.168.10.10): icmp_seq=3 ttl=64 time=0.061 ms
64 bytes from www.linuxprobe.com (192.168.10.10): icmp_seq=4 ttl=64 time=0.069 ms
--- www.linuxprobe.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.061/0.069/0.077/0.008 ms
[root@linuxprobe ~]# 第2步:分別在/home/wwwroot中創(chuàng)建用于保存不同網(wǎng)站數(shù)據(jù)的三個(gè)目錄,并向其中分別寫入網(wǎng)站的首頁文件。每個(gè)首頁文件中應(yīng)有明確區(qū)分不同網(wǎng)站內(nèi)容的信息,方便我們稍后能更直觀地檢查效果。
[root@linuxprobe ~]# mkdir -p /home/wwwroot/www
[root@linuxprobe ~]# mkdir -p /home/wwwroot/bbs
[root@linuxprobe ~]# mkdir -p /home/wwwroot/tech
[root@linuxprobe ~]# echo "WWW.linuxprobe.com" > /home/wwwroot/www/index.html
[root@linuxprobe ~]# echo "BBS.linuxprobe.com" > /home/wwwroot/bbs/index.html
[root@linuxprobe ~]# echo "TECH.linuxprobe.com" > /home/wwwroot/tech/index.html第3步:在httpd服務(wù)的配置文件中大約113行處開始,分別追加寫入三個(gè)基于主機(jī)名的虛擬主機(jī)網(wǎng)站參數(shù),然后保存并退出。記得需要重啟httpd服務(wù),這些配置才生效。
[root@linuxprobe ~]# vim /etc/httpd/conf/httpd.conf
………………省略部分輸出信息………………
113
114 DocumentRoot "/home/wwwroot/www"
115 ServerName "www.linuxprobe.com"
116
117 AllowOverride None
118 Require all granted
119
120
121
122 DocumentRoot "/home/wwwroot/bbs"
123 ServerName "bbs.linuxprobe.com"
124
125 AllowOverride None
126 Require all granted
127
128
129
130 DocumentRoot "/home/wwwroot/tech"
131 ServerName "tech.linuxprobe.com"
132
133 AllowOverride None
134 Require all granted
135
136
………………省略部分輸出信息………………第4步:因?yàn)楫?dāng)前的網(wǎng)站數(shù)據(jù)目錄還是在/home/wwwroot目錄中,因此還是必須要正確設(shè)置網(wǎng)站數(shù)據(jù)目錄文件的SELinux安全上下文,使其與網(wǎng)站服務(wù)功能相吻合。最后記得用restorecon命令讓新配置的SELinux安全上下文立即生效,這樣就可以立即訪問到虛擬主機(jī)網(wǎng)站了,效果如圖10-16所示。
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/www
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/www/*
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/bbs
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/bbs/*
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/tech
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/tech/*
[root@linuxprobe ~]# restorecon -Rv /home/wwwroot
reset /home/wwwroot context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/www context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/www/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/bbs context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/bbs/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/tech context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/tech/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
[root@linuxprobe ~]# firefox
圖10-16 基于主機(jī)域名訪問虛擬主機(jī)網(wǎng)站
當(dāng)前文章:創(chuàng)新互聯(lián)linux教程:10.5.2基于主機(jī)域名
當(dāng)前地址:http://fisionsoft.com.cn/article/cddcope.html


咨詢
建站咨詢
