Apache 与SELinux

配置Apache经常遇到的一个问题就是,Permission Denied,奇怪之处在于,我已经把owner:group都设置成apache,并且各级目录的访问权限也都正确设置,仍然还是在进行文件操作的时候Permission Denied.

问题的真正原因一般出在SELinux上。SELinux是「Security-Enhanced Linux」的简称,是美国国家安全局「NSA=The National Security Agency」 和SCC(Secure Computing Corporation)开发的 Linux的一个扩张强制访问控制安全模块。

我对它了解不多,简单的看就是在传统UNIX访问设置上又附加的一些访问控制属性。用ls -aZ命令看下比较清楚: 

 

  1. [root@localhost subversion]# ls -aZ *
  2. drwxr-xr-x  apache apache root:object_r:httpd_sys_content_t .
  3. drwxr-xr-x  apache apache root:object_r:usr_t              ..
  4. drwxr-xr-x  apache apache root:object_r:httpd_sys_content_t conf
  5. drwxr-xr-x  apache apache root:object_r:httpd_sys_content_t dav
  6. drwxr-xr-x  apache apache root:object_r:httpd_sys_content_t db
  7. -rw-r--r--  apache apache root:object_r:httpd_sys_content_t format
  8. drwxr-xr-x  apache apache root:object_r:httpd_sys_content_t hooks
  9. drwxr-xr-x  apache apache root:object_r:httpd_sys_content_t locks
  10. -rw-r--r--  apache apache root:object_r:httpd_sys_content_t README.txt

大家注意root:object_r:httpd_sys_content_t 这一列,就是第三个属性的值影响了Apache与它的关系。根据我机器(CentOS)上 SELinux的设置,需要把第三列设置成httpd_sys_content_t,apache才能正常访问这个目录里的内容。更改这个属性的值用chcon命令,(类似chown),比如:

chcon -R -h -t httpd_sys_content_t 
其中: -R 递归应用;-h 不要跟随符号链接; -t 属性值
如此设置后,就能够解决Permission Denied的问题了。

关闭SELinux:

修改档案/etc/sysconfig/selinux:

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=enforcing

# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted
把 SELINUX设定为disable, 下次启动系统后将会停止SElinux。

关于详细的Apache 与SELinux的设置和介绍,请看官方说明:Understanding and Customizing the Apache HTTP SELinux Policy

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值