日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)linux教程:10.5.3基于端口號

基于端口號的虛擬主機(jī)功能可以讓用戶通過指定的端口號來訪問服務(wù)器上的網(wǎng)站資源。在使用Apache配置虛擬網(wǎng)站主機(jī)功能時,基于端口號的配置方式是最復(fù)雜的。因此我們不僅要考慮httpd服務(wù)程序的配置因素,還需要考慮到SELinux服務(wù)對新開設(shè)端口的監(jiān)控。一般來說,使用80、443、8080等端口號來提供網(wǎng)站訪問服務(wù)是比較合理的,如果使用其他端口號則會受到SELinux服務(wù)的限制。

在接下來的實(shí)驗(yàn)中,我們不但要考慮到目錄上應(yīng)用的SELinux安全上下文的限制,還需要考慮SELinux域?qū)ttpd服務(wù)程序的管控。

第1步:分別在/home/wwwroot中創(chuàng)建用于保存不同網(wǎng)站數(shù)據(jù)的兩個目錄,并向其中分別寫入網(wǎng)站的首頁文件。每個首頁文件中應(yīng)有明確區(qū)分不同網(wǎng)站內(nèi)容的信息,方便我們稍后能更直觀地檢查效果。

    [root@linuxprobe ~]# mkdir -p /home/wwwroot/6111
    [root@linuxprobe ~]# mkdir -p /home/wwwroot/6222
    [root@linuxprobe ~]# echo "port:6111" > /home/wwwroot/6111/index.html
    [root@linuxprobe ~]# echo "port:6222" > /home/wwwroot/6222/index.html

第2步:在httpd服務(wù)配置文件的第43行和第44行分別添加用于監(jiān)聽6111和6222端口的參數(shù)。

    [root@linuxprobe ~]# vim /etc/httpd/conf/httpd.conf 
    ………………省略部分輸出信息……………… 
     33 #
     34 # Listen: Allows you to bind Apache to specific IP addresses and/or
     35 # ports, instead of the default. See also the 
     36 # directive.
     37 #
     38 # Change this to Listen on specific IP addresses as shown below to 
     39 # prevent Apache from glomming onto all bound IP addresses.
     40 #
     41 #Listen 12.34.56.78:80
     42 Listen 80
     43 Listen 6111
     44 Listen 6222
    ………………省略部分輸出信息……………… 

第3步:在httpd服務(wù)的配置文件中大約113行處開始,分別追加寫入兩個基于端口號的虛擬主機(jī)網(wǎng)站參數(shù),然后保存并退出。記得需要重啟httpd服務(wù),這些配置才生效。

    [root@linuxprobe ~]# vim /etc/httpd/conf/httpd.conf
    ………………省略部分輸出信息……………… 
    113 
    114 DocumentRoot "/home/wwwroot/6111"
    115 ServerName www.linuxprobe.com
    116 
    117 AllowOverride None
    118 Require all granted
    119  
    120 
    121 
    122 DocumentRoot "/home/wwwroot/6222"
    123 ServerName bbs.linuxprobe.com
    124 
    125 AllowOverride None
    126 Require all granted
    127 
    128 
    ………………省略部分輸出信息………………

第4步:因?yàn)槲覀儼丫W(wǎng)站數(shù)據(jù)目錄存放在/home/wwwroot目錄中,因此還是必須要正確設(shè)置網(wǎng)站數(shù)據(jù)目錄文件的SELinux安全上下文,使其與網(wǎng)站服務(wù)功能相吻合。最后記得用restorecon命令讓新配置的SELinux安全上下文立即生效。

    [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
    [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6111
    [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6111/*
    [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6222
    [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6222/*
    [root@linuxprobe ~]# restorecon -Rv /home/wwwroot/
    restorecon 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/6111 context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
    restorecon reset /home/wwwroot/6111/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
    restorecon reset /home/wwwroot/6222 context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
    restorecon reset /home/wwwroot/6222/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
    [root@linuxprobe ~]# systemctl restart httpd
    Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.

見鬼了!在妥當(dāng)配置httpd服務(wù)程序和SELinux安全上下文并重啟httpd服務(wù)后,竟然出現(xiàn)報錯信息。這是因?yàn)镾ELinux服務(wù)檢測到6111和6222端口原本不屬于Apache服務(wù)應(yīng)該需要的資源,但現(xiàn)在卻以httpd服務(wù)程序的名義監(jiān)聽使用了,所以SELinux會拒絕使用Apache服務(wù)使用這兩個端口。我們可以使用semanage命令查詢并過濾出所有與HTTP協(xié)議相關(guān)且SELinux服務(wù)允許的端口列表。

    [root@linuxprobe ~]# semanage port -l | grep http
    http_cache_port_t tcp 8080, 8118, 8123, 10001-10010
    http_cache_port_t udp 3130
    http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
    pegasus_http_port_t tcp 5988
    pegasus_https_port_t tcp 5989

第5步:SELinux允許的與HTTP協(xié)議相關(guān)的端口號中默認(rèn)沒有包含6111和6222,因此需要將這兩個端口號手動添加進(jìn)去。該操作會立即生效,而且在系統(tǒng)重啟過后依然有效。設(shè)置好后再重啟httpd服務(wù)程序,然后就可以看到網(wǎng)頁內(nèi)容了,結(jié)果如圖10-17所示。

    [root@linuxprobe ~]# semanage port -a -t http_port_t -p tcp 6111
    [root@linuxprobe ~]# semanage port -a -t http_port_t -p tcp 6222
    [root@linuxprobe ~]# semanage port -l| grep http
    http_cache_port_t tcp 8080, 8118, 8123, 10001-10010
    http_cache_port_t udp 3130
    http_port_t tcp  6222, 6111, 80, 81, 443, 488, 8008, 8009, 8443, 9000
    pegasus_http_port_t tcp 5988
    pegasus_https_port_t tcp 5989
    [root@linuxprobe ~]# systemctl restart httpd
    [root@linuxprobe ~]# firefox

圖10-17 基于端口號訪問虛擬主機(jī)網(wǎng)站


分享標(biāo)題:創(chuàng)新互聯(lián)linux教程:10.5.3基于端口號
URL鏈接:http://www.5511xx.com/article/dheshsg.html