Centos7 nginx提示错误 Access denied.

本文介绍了解决CentOS/RHEL7+系统中因SELinux导致的访问权限问题的方法。包括临时禁用SELinux进行测试,调整策略使PHP-FPM能够访问Web文件,以及恢复SELinux上下文。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

SELinux will cause this error on CentOS/RHEL 7+ by default :(

CentOS/RHEL 7+ 系统默认会因为SELinux出现这个报错

 

To test if SELinux is the source of your woes, do

你可以通过下面这个命令关闭SELinux,进行测试

setenforce 0

 

... and see if everything works. If that fixed it, you can leave SELinux off (weak, you're better than that), or you can turn it back on with

看看是否运行正常,如果成功修复了,你可以修改配置文件永久保留关闭,或者再打开SELinux

setenforce 1

 

... and then properly fix the issue.

然后妥善解决这个问题。

 

If you do

如果你执行

tail -f /var/log/audit/audit.log

 

... you'll see the SELinux issue. In my case, it was denying PHP-FPM access to web files. You can run the following directives to fix it:

你将会看到是SELinux的问题。在我看来,这是因为SELinux拒绝了PHP-FPM访问Web文件。您可以运行以下指令来修复它:

setsebool -P httpd_can_network_connect_db 1
setsebool -P httpd_can_network_connect 1

 

This actually didn't fix it for me at first, but then restoring SELinux context did it

这一步还没有完全修复好,继续执行下面命令修复上下文

restorecon -R -v /var/www(你的web目录)

 

Hope that helps.

希望能帮到你

 

作者:匿名用户

链接:https://www.zhihu.com/question/22128267/answer/105600681

来源:知乎

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

转载于:https://www.cnblogs.com/zhaijiahui/p/8449371.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值