本文共 1240 字,大约阅读时间需要 4 分钟。
在CentOS 7.5配置Apache HTTP服务器后,看到如下错误:
Permission denied
查看Apache HTTP服务器的错误日志/var/log/httpd/error_log如下:
[Wed May 06 23:00:54 2019] [error] [client 127.0.0.1] (13) Permission denied: access to /www/t.txt denied
查看SELinux的审计日志如下:
[root@myhost ~]# grep denied /var/log/audit/audit.logtype=AVC msg=audit(1415715270.766:31): avc: denied { getattr } for pid=1380 comm="httpd" path="/www/t.txt" dev=vda1 ino=1084 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file
通过审计日志,我们看到Apache进程的scontext type为httpd_t,而被请求对象的tcontext type为default_t,所以Apache进程访问/www/t.txt文件被拒绝。
执行grep 1415715270.766:31 /var/log/audit/audit.log | audit2why命令,让audit2why帮助我们找到解决办法。该命令给出建议:
You can use audit2allow to generate a loadable module to allow this access.于是得到如下解决方案:
解决方案一:临时改变/www/t.txt文件的SELinux type
chcon --type=httpd_sys_content_t /www/t.txt 或chcon -t httpd_sys_content_t /www/t.txt解决方案二:永久改变/www/t.txt文件的SELinux type
semanage fcontext -a -t httpd_sys_content_t /www/t.txt restorecon -v /www/t.txt解决方案三:永久改变/www目录的SELinux type
semanage fcontext -a -t httpd_sys_content_t /www(/.*)? restorecon -Rv /www解决方案四:改变httpd_t的访问范围
grep nginx /var/log/audit/audit.log | audit2allow -M myapache semodule -i myapache.pp
转载地址:http://xhlai.baihongyu.com/