1. 程式人生 > >centos 7上nginx 報錯,open() "test.min.css" failed (13: Permission denied

centos 7上nginx 報錯,open() "test.min.css" failed (13: Permission denied

OS: Centos7

Kernal: 3.10.0-327.el7.x86_64

在配置好django及相應的nginx反向代理後

發現web開啟沒有找到靜態檔案,nginx日誌報permission denied, 檢查過程如下:

1. 檢查/var/www/static目錄的屬主和許可權,發現屬主非www(nginx worker以www使用者啟動),許可權正確

    chown -R www.www /var/www/static

        修改後發現仍然沒有靜態檔案

2. 沒辦法,google,發現stackoverflow如下回答:

I've just had the same problem on a CentOS 7 box.

Seems I'd hit selinux. Putting selinux into permissive mode (setenforce permissive) has worked round the problem for now. I'll try and get back with a proper fix.

在命令列執行指令setenforce permissive後重新整理恢復

這種辦法只是把selinux的安全級別降低了,至於如何徹底解決,還在研究

補充:

經過不停的google+各種關鍵詞,終於找到徹底解決辦法:

1. 安裝audit.log的相關分析工具集

yum install setroubleshoot

2.  產生可訪問的白名單

cat /var/log/audit/audit.log| grep nginx |audit2allow -M mynginx

3. 使白名單生效

semodule -i mynginx.pp

4. 恢復selinux預設功能

setenforce enforcing

再次重新整理頁面,靜態檔案正常,問題解決

附上selinux的介紹:

SELinux(Security-Enhanced Linux) 是美國國家安全域性(NSA)對於強制訪問控制的實現,是 Linux歷史上最傑出的新安全子系統。NSA是在Linux社群的幫助下開發了一種訪問控制體系,在這種訪問控制體系的限制下,程序只能訪問那些在他的任務中所需要檔案