您的位置:首页 > 运维架构 > Apache

Apache 与SELinux

2009-01-05 11:52 169 查看
配置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命令看下比较清楚:

[root@localhost subversion]# ls -aZ *

drwxr-xr-x apache apache root:object_r:httpd_sys_content_t .

drwxr-xr-x apache apache root:object_r:usr_t ..

drwxr-xr-x apache apache root:object_r:httpd_sys_content_t conf

drwxr-xr-x apache apache root:object_r:httpd_sys_content_t dav

drwxr-xr-x apache apache root:object_r:httpd_sys_content_t db

-rw-r--r-- apache apache root:object_r:httpd_sys_content_t format

drwxr-xr-x apache apache root:object_r:httpd_sys_content_t hooks

drwxr-xr-x apache apache root:object_r:httpd_sys_content_t locks

-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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: