一.下载软件包
[root@localhost ~]# yum install policycoreutils-python-utils -y [root@localhost ~]# yum install setroubleshoot-server -y 注意: 下载前需要先挂载,因为我之前的实验已经下载了httpd软件包,在这里就没有下载了,没有的需要下载。  这样就下载ok了。
二.创建目录,写入内容
[root@localhost ~]# mkdir /www/test [root@localhost ~]# cd /www [root@localhost www]# echo welcome to test >test/index.html

三.写配置文件
[root@localhost ~]# cd /etc/httpd/conf.d [root@localhost conf.d]# vim host.conf
<directory /www>
allowoverride
require all granted
</directory>
listen 9091
<virtualhost 0.0.0.0:9091>
documentroot /www/test
servername 192.168.24.129
</virtualhost>


四.启动httpd服务并检查状态
[root@localhost conf.d]# systemctl start httpd 
会有报错。提示为不能绑定端口。
五.SELinux策略运行在9091端口
[root@localhost conf.d]# semanage port -l | grep http

SELinux策略在httpd的80端口上运行的,我们现在需要让它在9091上面运行: [root@localhost conf.d]# semanage port -a -t http_port_t -p tcp 9091 [root@localhost conf.d]# semanage port -l | grep http 
六.重启服务
[root@localhost conf.d]# systemctl start httpd [root@localhost conf.d]# systemctl status httpd
 服务就启用在9091和80端口
七.排查内容无法访问的原因
[root@localhost conf.d]# wget 192.168.24.129:9091 访问时报错  [root@localhost conf.d]# sealert -l “*” | grep preventing 排查原因  最后一行提示我们说,需要让/www/test/index.html 获取到服务器访问权限。
也可以使用matchpathcon工具比较标准SELinux类型和新路径 [root@localhost conf.d]# matchpathcon /var/www/html /www/test (注意空格)  /var/www/html是默认路径,也就是允许 Apache(web 服务器进程作为 httpd_t 运行)访问的路径。/www/test 是我们定义的新路径。 通过比对发现:/var/www/html 的标签是httpd_sys_content_t。/www/test 标签是default_t。标签对不上就不能访问,所以我们接下来需要修改标签
八.修改标签
将新 /var/test_www/html/ 内容目录的 SELinux 类型改为默认 /var/www/html 目录的类型: [root@localhost conf.d]# semanage fcontext -a -e /var/www/html /www/test [root@localhost conf.d]# matchpathcon /var/www/html /www/test 
九.递归重新标记 /www/test 目录
[root@localhost conf.d]# restorecon -Rv /www/test [root@localhost conf.d]# ll /www/test -Z

十.验证:
-
检查 httpd 服务是否正在运行 [root@localhost conf.d]# systemctl status httpd  -
验证 Apache HTTP 服务器提供的内容是否可以访问 [root@localhost conf.d]# wget 192.168.24.129:9091
 [root@localhost conf.d]# wget 192.168.24.129:9091/index.html  成功访问到。这个实验就结束了。
|