CentOS (Vagrant) 上的 nginx 403 被禁止

CentOS (Vagrant) 上的 nginx 403 被禁止

到目前為止我已經檢查過的內容:

日誌 - 它們是空的,啟動了新的虛擬機器。

權限:

$ namei -l /var/www/awesome/    
f: /var/www/awesome/    
dr-xr-xr-x root     root     /    
drwxr-xr-x root     root     var    
drwxrwxr-x www-data www-data www
drwxrwxr-x www-data www-data awesome

將 777 指派給包含 vagrant 檔案的主機作業系統資料夾。

啟用 SELinux。

儘管如此,即使在使用 curl localhost 的虛擬機器內,我也會得到 403。

這是 Awesome.dev 的 nginx 配置

server {
   listen                *:80;

   server_name           awesome.dev www.awesome.dev;
     index  index.html index.htm index.php;

   access_log            /var/log/nginx/awesome.dev.access.log;
   error_log             /var/log/nginx/awesome.dev.error.log;

   location / {
     root  /var/www/awesome;
     try_files $uri $uri/ index.php /index.php$is_args$args;
   }
   location ~ \.php$ {
     root  /var/www/awesome;
     index  index.html index.htm index.php;
     fastcgi_index index.php;
     fastcgi_param SCRIPT_FILENAME $request_filename;
     fastcgi_param APP_ENV dev;
     fastcgi_pass 127.0.0.1:9000;
     fastcgi_split_path_info ^(.+\.php)(/.*)$;
     include fastcgi_params;
   }
   sendfile off;
 }

如何解決這個問題?

答案1

CentOS 7 也有同樣的問題。

Check getenforce

這應該顯示“強制執行”

然後我運行chcon更改 httpd 安全上下文以允許存取。

chcon -Rt httpd_sys_content_t /path/to/web/content

重新載入 Nginx

systemctl restart nginx

現在我的頁面加載了。

答案2

其內容/var/www/awesome/及其權限為何?

如果沒有index.html,index.htmindex.php文件,nginx 將嘗試列出目錄內容,預設這是禁止的(參見autoindex文件).

相關內容