博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SELinux检查与Apache HTTP服务器的文件访问典型错配案例及解决
阅读量:4179 次
发布时间:2019-05-26

本文共 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/

你可能感兴趣的文章
Flex开发debug集合
查看>>
Sql Server 2008 连接 Oracle11数据库
查看>>
远程到服务器,页面为桌面背景,没有图标
查看>>
Oracle连接Sql Server (win32_11gR2_gateways)
查看>>
ORA-00600: 内部错误代码, 参数: [19004]
查看>>
Window Server 2008 R2 数据泵自动备货
查看>>
PowerDesigner 转换Word
查看>>
APP接口签名算法
查看>>
mkdir(): Permission denied
查看>>
使用redis优化性能之注册和登录
查看>>
Runtime error——Explorer.EXE
查看>>
redis事务
查看>>
file_get_contents无法获取到https开头的链接内容问题
查看>>
mysql的order by排序不正确的问题
查看>>
在windows中安装RabbitMQ扩展
查看>>
linux下redis的安装及配置开机启动
查看>>
redis添加访问密码
查看>>
linux服务器安全优化之使用子账户远程登录
查看>>
windows安装打印机时,提示正在检查windows更新。这可能需要一段时间...
查看>>
fiddler无法抓包
查看>>