假设你的 Nginx 配置没有任何问题,并且运行 getenforce 的结果是 Enforcing。
首先你要让 SELinux 允许 httpd[1] 访问用户目录。很简单,root 运行 setsebool -P httpd_enable_homedirs 。
"-P" 的意思是 permanent,不带 -P 的话系统重启后恢复默认配置。
然后你要修改 /home/user/static 的 SELinux context。告诉 SELinux,允许此目录被 httpd 访问:
chcon -v -t httpd_user_content_t /home/user/static
没有意外的话应该就可以访问了。
简单易懂的关于 SELinux 的讲座:
Red Hat 出的 SELinux 手册:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/SELinux_Users_and_Administrators_Guide/index.html更多和 httpd 有关的 SELinux 开关:
getsebool -a | grep httpd
安装 selinux-policy-devel,然后 man httpd_selinux
[1] 在 RHEL/CentOS/Fedora 下,
httpd 包是 apache。但 apache 和 nginx 的 SELinux context 都是:system_u:system_r:httpd_t:s0。