99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

10.5.2 基于主機(jī)域名

2023-05-12 10:59 更新

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

第1步:手工定義IP地址與域名之間對(duì)應(yīng)關(guān)系的配置文件,保存并退出后會(huì)立即生效??梢酝ㄟ^(guò)分別ping這些域名來(lái)驗(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è)目錄,并向其中分別寫(xiě)入網(wǎng)站的首頁(yè)文件。每個(gè)首頁(yè)文件中應(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行處開(kāi)始,分別追加寫(xiě)入三個(gè)基于主機(jī)名的虛擬主機(jī)網(wǎng)站參數(shù),然后保存并退出。記得需要重啟httpd服務(wù),這些配置才生效。

    [root@linuxprobe ~]# vim /etc/httpd/conf/httpd.conf
    ………………省略部分輸出信息………………
    113 <VirtualHost 192.168.10.10>
    114 DocumentRoot "/home/wwwroot/www"
    115 ServerName "www.linuxprobe.com"
    116 <Directory "/home/wwwroot/www">
    117 AllowOverride None
    118 Require all granted
    119 </directory> 
    120 </VirtualHost>
    121 <VirtualHost 192.168.10.10>
    122 DocumentRoot "/home/wwwroot/bbs"
    123 ServerName "bbs.linuxprobe.com"
    124 <Directory "/home/wwwroot/bbs">
    125 AllowOverride None
    126 Require all granted
    127 </Directory>
    128 </VirtualHost>
    129 <VirtualHost 192.168.10.10>
    130 DocumentRoot "/home/wwwroot/tech"
    131 ServerName "tech.linuxprobe.com"
    132 <Directory "/home/wwwroot/tech">
    133 AllowOverride None
    134 Require all granted
    135 </directory>
    136 </VirtualHost>
    ………………省略部分輸出信息………………

第4步:因?yàn)楫?dāng)前的網(wǎng)站數(shù)據(jù)目錄還是在/home/wwwroot目錄中,因此還是必須要正確設(shè)置網(wǎng)站數(shù)據(jù)目錄文件的SELinux安全上下文,使其與網(wǎng)站服務(wù)功能相吻合。最后記得用restorecon命令讓新配置的SELinux安全上下文立即生效,這樣就可以立即訪問(wèn)到虛擬主機(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ī)域名訪問(wèn)虛擬主機(jī)網(wǎng)站

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)