2017-01-23 61 views
0

我對Nginx相當陌生。我配置的Nginx使用virtualhosts(服務器模塊)並重新啓動nginx的,但我得到兩個錯誤,使沒有意義的我...CentOS 7 + Nginx + Google Compute Engine(權限禁止錯誤)

這是我的虛擬主機服務塊看起來像

server { 
listen 80 default_server; 
listen [::]:80 default_server; 

root /custom/path/to/public_html; 
index index.html index.htm index.php; 
server_name _; 
#access_log /custom/path/to/log/oq.default.access.log combined buffer=1024k; 
#error_log /custom/path/to/log/oq.default.error.log; 

location/{ 
    try_files $uri $uri/ =404; 
} 

error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
    root html; 
} 

}

錯誤編號#1:註釋出所述的access_log線之前 ,nginx的將無法啓動,並顯示以下錯誤2017/01/23 02:10:23 [emerg] 26984#0: open() "/custom/path/to/log/oq.default.access.log" failed (13: Permission denied)

錯誤編號#2: 註釋掉訪問日誌行後,重新啓動nginx的(成功),這時候我得到我的網站上的錯誤403禁止,當我去到錯誤日誌它顯示我

2017/01/23 11:32:10 [error] 5812#0: *3 "/custom/path/to/public_html/index.html" is forbidden (13: Permission denied), client: xxx.xxx.xxx.xxx, server: _, request: "GET/HTTP/1.1", host: "xxx.xxx.xxx.xxx"

我設置777 BOTH「的public_html」和「日誌」文件夾和我改變所有者「nginx的:nginx的」,然後重新啓動nginx的,目前仍是同樣的錯誤仍然出來

什我錯過了嗎?

+0

這是另一條線索 - 如果我將我的index.html頁面到/ usr /共享/ nginx的/ HTML(調整我的conf文件複製到新根),重新啓動nginx和重新加載我的頁面 - 一切正常......但如果我離開我的自定義路徑:/ my/custom/path/public_html(調整我的conf文件到這個根目錄),重新啓動nginx並重新加載我的頁面 - 它打破權限拒絕錯誤... 兩個路徑具有相同的確切權限 - UGH! –

+0

這可能是SELinux引起的問題嗎? –

回答

1

它的SELinux:

grep nginx /var/log/audit/audit.log | audit2allow -m nginx > nginx.te 
cat nginx.te 
grep nginx /var/log/audit/audit.log | audit2allow -M nginx 
semodule -i nginx.pp 
+0

SELinux的確是問題所在,我禁用了它,並且必須在所有工作成功之前重新啓動盒子 –