Selinux介绍 及 解决 nginx跟换目录出现Permission denied的问题

介绍:SELinux

nginx跟换目录出现Permission denied的问题:

前提: 跟换后的目录读写权都是可用的(即便root给了 777 权限 也出现了该问题)
在contos 7 种 SElinux 是默认为enforcing
方法1
修改配置文件

[root]$ vi /etc/selinux/config

将 SELINUX=enforcing 修改为:SELINUX=disabled
重启主机
当将 SELINUX=disabled修改为:SELINUX=enforcing 再重启主机是,时间会很长,因为要花很长时间去写入SELinux,重启后最好在重启一次;所以需两次重启

[root]$ init 6

方法2 (建议使用):
例如将nginx默认路径:/usr/share/nginx/html/改为: /home/html/

[root]$ chcon -R --reference=/usr/share/nginx/html/ /home/html/

或者

[root]$ ls -Zd /usr/share/nginx/html /home/html
drwxr-xr-x. root   root   system_u:object_r:home_root_t:s0 /home/html
drwxr--r--. apache apache system_u:object_r:httpd_sys_content_t:s0 /usr/share/nginx/html
//可用看出两个文件的不同之处了 home_root_t  !=  httpd_sys_content_t
//所以只需要将 /home/html的home_root_t  改为httpd_sys_content_t
[root]$ chcon -R -t httpd_sys_content_t  /home/html

参考:
https://baike.baidu.com/item/SELinux/8865268?fr=aladdin

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容