centos7上配置SELinux允许nginx指定/home/www作为网站根目录


现象:

1 启动nginx成功,使用wget 127.0.0.1得到内容,但是提示是禁止访问(403);

2 查看/var/log/nginx/error.log,提示访问/home/www/l.com/i.html禁止;

3 查看SELinux 是否运行: sestatus -v,enable就是运行了

4查看/var/log/Audit/Audit.log日志,发现有提示到nginx被拒绝了;但是看不明白怎么处理...

它是类似这样的内容

type=AVC msg=audit(1416406823.013:3137): avc:  denied  { search } for  pid=15488 comm="nginx" name="www" dev="dm-3" ino=146 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_home_dir_t:s0 tclass=dir
5 安装人类能看得懂的转化工具:yum install setroubleshoot

 

6 echo >audit.log来清空这个日志,再刷新浏览器,访问一下这个url,让只生成一个出错日志

7 把出错内容转成可以看得懂的:sealert -a ./audit.log >qq.txt

8查看内容:cat qq.txt:

[root@l audit]# cat qq.txt
string index out of range
'list' object has no attribute 'split'

found 1 alerts in ./audit.log
--------------------------------------------------------------------------------

SELinux is preventing /usr/sbin/nginx from search access on the directory .

*****  Plugin catchall_boolean (47.5 confidence) suggests   ******************

If 您要 allow httpd to read user content
Then 您必须启用 'httpd_read_user_content' 布尔值告知 SELinux 此情况。

Do
setsebool -P httpd_read_user_content 1

*****  Plugin catchall_boolean (47.5 confidence) suggests   ******************

If 您要 allow httpd to enable homedirs
Then 您必须启用 'httpd_enable_homedirs' 布尔值告知 SELinux 此情况。

Do
setsebool -P httpd_enable_homedirs 1

*****  Plugin catchall (6.38 confidence) suggests   **************************

If 您确定应默认允许 nginx search 访问  directory。
Then 您应该将这个情况作为 bug 报告。
您可以生成本地策略模块允许这个访问。
Do
请执行以下命令此时允许这个访问:
# grep nginx /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp


Additional Information:
Source Context                system_u:system_r:httpd_t:s0
Target Context                unconfined_u:object_r:user_home_dir_t:s0
Target Objects                 [ dir ]
Source                        nginx
Source Path                   /usr/sbin/nginx
Port                          <Unknown>
Host                          <Unknown>
Source RPM Packages           nginx-1.6.2-4.el7.x86_64
Target RPM Packages
Policy RPM                    selinux-policy-3.12.1-153.el7_0.11.noarch
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Enforcing
Host Name                     l.com
Platform                      Linux l.com 3.10.0-123.9.3.el7.x86_64 #1 SMP Thu
                              Nov 6 15:06:03 UTC 2014 x86_64 x86_64
Alert Count                   13
First Seen                    2014-11-19 22:32:40 CST
Last Seen                     2014-11-19 22:24:28 CST
Local ID                      bb55eec2-48bf-44eb-9722-7ca6f1045a59

Raw Audit Messages
type=AVC msg=audit(1416407068.287:3141): avc:  denied  { search } for  pid=15488 comm="nginx" name="www" dev="dm-3" ino=146 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_home_dir_t:s0 tclass=dir


type=SYSCALL msg=audit(1416407068.287:3141): arch=x86_64 syscall=open success=no exit=EACCES a0=7f0661e65bc0 a1=800 a2=0 a3=0 items=0 ppid=15487 pid=15488 auid=4294967295 uid=997 gid=996 euid=997 suid=997 fsuid=997 egid=996 sgid=996 fsgid=996 tty=(none) ses=4294967295 comm=nginx exe=/usr/sbin/nginx subj=system_u:system_r:httpd_t:s0 key=(null)

Hash: nginx,httpd_t,user_home_dir_t,dir,search

[root@l audit]#

 

9 按提示一步一步处理成功了就可以了.

相关内容