SELinux个人学习:[1]解决web网站无法访问
1、setroubleshoot
用于把SELinux 的错误讯息与克服方法记录到 /var/log/messages 与 /var/log/setroubleshoot/* 里头,所以一定要启动该服务。
所以我们先来安装。
输入一下命令安装。
# yum install setroubleshoot setroubleshoot-server
![SELinux个人学习:[1]解决web网站无法访问](https://exp-picture.cdn.bcebos.com/b1454a1bd10ff226ecac3eba9c99e92abbb8a48e.jpg)
2、安装之后,要重新启动 auditd,否则 setroubleshootd 的功能不会被启动的
输入以下命令
# service auditd restart
![SELinux个人学习:[1]解决web网站无法访问](https://exp-picture.cdn.bcebos.com/94af5fc1b727ac53e8be9e982ecadce89148998e.jpg)
3、在浏览器输入网页地址。
显示一下信息,这个时候错误的信息就被记录了。
Forbidden
You don't have permission to access /index.html on this server.
![SELinux个人学习:[1]解决web网站无法访问](https://exp-picture.cdn.bcebos.com/91091efc77f7980ea9164cc5d4db3620b83a918e.jpg)
4、输入一下命令。来查看错误信息
# cat /var/log/messages | grep setroubleshoot
Apr 21 23:34:37 centos setroubleshoot: SELinux is preventing /usr/sbin/httpd from getattr access on the file /var/www/html/index.html. For complete SELinux messages. run sealert -l 47d2c8e2-308b-4931-ae63-88bb4f518155
最重要的是
sealert -l 47d2c8e2-308b-4931-ae63-88bb4f518155
![SELinux个人学习:[1]解决web网站无法访问](https://exp-picture.cdn.bcebos.com/b87bd38920c5260f7603d23ed2de45078901898e.jpg)
5、输入之前找到的信息
sealert -l 47d2c8e2-308b-4931-ae63-88bb4f518155
显示以下内容
SELinux is preventing /usr/sbin/httpd from getattr access on the 文件 /var/www/html/index.html.
***** 插件 restorecon (99.5 置信度) 建议 ******************************************
If 您想要修复标签。
/var/www/html/index.html 默认标签应为 httpd_sys_content_t。
Then 您可以运行 restorecon。
Do
# /sbin/restorecon -v /var/www/html/index.html
***** 插件 catchall (1.49 置信度) 建议 ********************************************
If 您确定应默认允许 httpd getattr 访问 index.html file。
Then 您应该将这个情况作为 bug 报告。
您可以生成本地策略模块允许这个访问。
Do
请执行以下命令此时允许这个访问:
# grep httpd /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp
![SELinux个人学习:[1]解决web网站无法访问](https://exp-picture.cdn.bcebos.com/444696013870d5413fbba9bc2e0f94fc518c808e.jpg)
6、从上面的内容,就已经提示你解决的方法。
If 您想要修复标签。
/var/www/html/index.html 默认标签应为 httpd_sys_content_t。
Then 您可以运行 restorecon。
Do
# /sbin/restorecon -v /var/www/html/index.html
所以输入# /sbin/restorecon -v /var/www/html/index.html
网站可以正常浏览了。