美文网首页
Selinux介绍 及 解决 nginx跟换目录出现Permis

Selinux介绍 及 解决 nginx跟换目录出现Permis

作者: ling_1992 | 来源:发表于2018-06-16 12:03 被阅读0次

介绍: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

相关文章

网友评论

      本文标题:Selinux介绍 及 解决 nginx跟换目录出现Permis

      本文链接:https://www.haomeiwen.com/subject/fzgyeftx.html