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:
关于详细的Apache 与SELinux的设置和介绍,请看官方说明:Understanding and Customizing the Apache HTTP SELinux Policy
问题的真正原因一般出在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
相关文章推荐
- 一个Apache访问权限问题(万恶的SELinux)
- 由于SELinux开启造成的Apache 2 Test Page powered by CentOS
- 修改APACHE端口后启动出错,原来是SELINUX安全问题。
- SELinux 环境下网络服务设置 , 配置 Apache 、Samba、NFS、vsftp 、MySQL、Bind DNS
- Apache 403错误&SELinux解决方案
- [转载]SELinux 环境下网络服务设置,配置 Apache 、Samba、NFS
- apache php selinux --Syntax error 无法加载模块 推荐
- redhat server 6.0 Apache配置中的SELINUX问题
- Selinux_Apache
- 如果防火墙和selinux都开了,apache不能使用的原因
- CentOS6.5 服务器+apache5.3绑定多个域名+SELinux设置
- apache遇上selinux
- 搞定了Apache虚拟目录的SELinux权限
- selinux 限制 apache exec执行cgi
- apache遇上selinux(apache 不能创建文件问题解决)
- [转]Apache 监听端口失败,selinux惹的祸
- selinux导致apache虚拟主机目录不能访问
- SELinux中的Apache和MySQL设定
- 有SELinux引起的Apache基于端口的虚拟主机启动失败
- centos 5.5 开启selinux支持apache ftp phpmyadmin方案