SELinux对网站目录权限控制的不当的问题

本文记录了在Linux环境下,针对SELinux政策启用时,Apache服务运行上下文出现权限控制不当的问题。通过调整SELinux上下文,特别是使用chcon命令更改权限,使得网站目录权限与其他目录匹配为httpd_sys_content_t,从而解决了权限问题。

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

apache 报错

[Fri Jul 01 06:11:00 2016] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0
[Fri Jul 01 06:11:00 2016] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Fri Jul 01 06:11:01 2016] [notice] Digest: generating secret for digest authentication ...
[Fri Jul 01 06:11:01 2016] [notice] Digest: done


所以使用chcon更改SELinux权限以及显示结果如下:

<span style="color:#FF0000;">setenforce 0 #必须暂时停止SELinux,否则可能导致操作失败。 
chcon -t httpd_sys_content_t -R /var/www/html/home_start/ #R参数是递归操作的意思</span>



经过修改就会发现SELinux的对应权限已经和其他目录相同了!都是httpd_sys_content_t。

  1. [root@localhost html]# setenforce --help 
  2. usage:  setenforce [ Enforcing | Permissive | 1 | 0 ] 
  3. [root@localhost html]# setenforce 0 
  4. [root@localhost html]# cd 
  5. [root@localhost ~]# ls /var/www/html/trunk/gz -Z 
  6. ……
  7. drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 gz
  8. ……
  9. [root@localhost ~]# chcon -t httpd_sys_content_t -R /var/www/html/gz
  10. [root@localhost ~]# ls /var/www/html/trunk/gz/ -Z 
  11. ……
  12. -rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 authorize.php
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值