Centos7 nginx報錯403 forbidden
參考鏈接:http://www.cnblogs.com/chinway/archive/2017/08/14/7356239.html
因為安全性的考慮這個也是默認會出現的錯誤,因為SELinux的存在:(
提供兩種解決方案:
方式一:
網上大多數是關閉SELinux的方式(我自己不建議關閉),類似於這樣
步驟一:
檢查目錄權限。權限不足的就加個權限吧。
例子:chmod -R 755 / var/www
步驟二:
打開nginx.conf
例子:vim /etc/nginx/nginx.conf
把 user 用戶名 改為 user root 或 其它有高權限的用戶名稱即可
步驟三:
如果是centos,看一下selinux是否關閉了
查看SELinux狀態:
1、/usr/sbin/sestatus -v ##如果SELinux status參數為enabled即為開啟狀態
SELinux status: enabled
2、getenforce ##也可以用這個命令檢查
關閉SELinux:
1、臨時關閉(不用重啟機器):
setenforce 0 ##設置SELinux 成為permissive模式
##setenforce 1 設置SELinux 成為enforcing模式
2、修改配置文件需要重啟機器:
修改/etc/selinux/config 文件
將SELINUX=enforcing改為SELINUX=disabled
重啟機器即可
方式二:
另一種方法不關閉SELinux,並通過這種方法實現了web訪問
參考鏈接:http://blog.csdn.net/qidizi/article/details/41291397
記錄一下工具安裝和使用
安裝人類能看得懂的轉化工具:yum install setroubleshoot
echo >audit.log來清空這個日誌,再刷新瀏覽器,訪問一下這個url,讓只生成一個出錯日誌
把出錯內容轉成可以看得懂的:sealert -a ./audit.log >qq.txt
通過轉換的結果分析,執行以下命令:
sudo cat /var/log/audit/audit.log | grep nginx | grep denied | sudo audit2allow -M mynginx sudo semodule -i mynginx.pp
Centos7 nginx報錯403 forbidden