一台装有RHEL 7.0操作系统的电脑
分别在/home/wwwroot中创建两个用于保存不同网站数据的目录,并向其中分别写入网站的首页文件,每个首页文件中应有明确区分不同网站内容的字样信息,方便咱们稍后能更直观的检查效果:[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
在httpd服务的配置文件中大约43行后追加上监听6111和6222端口号的参数:[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
在httpd服务的配置文件中大约114行处,分别追加写入两个基于端口号的虚拟主机网站参数,保存退出文件后记得要重启httpd服务才能生效哦:[root@linuxprobe ~]# vim /etc/httpd/conf/httpd.conf ………………省略部分输出信息………………
还是因为咱们将网站数据目录存放在了/home/wwwroot中,因此还是必须要把网站数据目录文件上面的SELinux安全上下文设置好,让文件上面的SELinux安全上下文与网站服务功能相吻合,最后还是要记得用restorecon命令让新配置的SELinux安全上下文立即生效呢:[root@linuxprobe ~]# semanage fcontext -a -t httpd_user_content_t /home/wwwroot [root@linuxprobe ~]# semanage fcontext -a -t httpd_user_content_t /home/wwwroot/6111 [root@linuxprobe ~]# semanage fcontext -a -t httpd_user_content_t /home/wwwroot/6111/* [root@linuxprobe ~]# semanage fcontext -a -t httpd_user_content_t /home/wwwroot/6222 [root@linuxprobe ~]# semanage fcontext -a -t httpd_user_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_user_content_t:s0 restorecon reset /home/wwwroot/6111 context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_user_content_t:s0 restorecon reset /home/wwwroot/6111/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_user_content_t:s0 restorecon reset /home/wwwroot/6222 context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_user_content_t:s0 restorecon reset /home/wwwroot/6222/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_user_content_t:s0 [root@linuxprobe ~]# systemctl restart httpd Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.什么??!!在咱们把httpd服务程序和SELinux安全上下文都配置妥当后,重启服务为什么会竟然出现报错信息呢?这是因为SELinux服务检测到6111和6222端口原本不属于apache应该需要的服务资源,但现在却被以httpd服务程序的名义监听使用了,便会直接拒绝掉了,咱们可以用semanage命令查询并过滤出所有与http协议相关的端口号SElinux允许列表:[root@linuxprobe ~]# semanage port -l| grep http http_cache_port_t tcp 8080, 8118, 8123, 1 http_cache_port_t udp 3130 http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000pegasus_http_port_t tcp 5988 pegasus_https_port_t tcp 5989
SELinux允许http协议使用的端口号中默认没有包含咱们的6111和6222,因此需要手动的添加进去就可以了,操作会立即生效,且重启过后依然有效,因此设置后再重启一下httpd服务程序就能看到网页内容了,如图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, 1http_cache_port_t udp 3130 http_port_t tcp 6222, 6111, 80, 81, 443, 488, 8008, 8009, 8443, 9000pegasus_http_port_t tcp 5988 pegasus_https_port_t tcp 5989 [root@linuxprobe ~]# systemctl restart httpd [root@linuxprobe ~]# firefox