首頁  >  文章  >  運維  >  Nginx網站根目錄更改導致403怎麼解決

Nginx網站根目錄更改導致403怎麼解決

WBOY
WBOY轉載
2023-05-18 10:28:121069瀏覽

一、更改根目錄

nginx預設網站根目錄為/usr/local/nginx/html,將它改成/home/fuxiao/www

#更改方法:

vi /usr/local/nginx/conf/nginx.conf

將其中的

location / {
      root  html;
      index index.php index.html index.htm;
    }

改為

location / {
      root  /home/fuxiao/www;
      index index.php index.html index.htm;
    }

然後再將

location ~ \.php$ {
      root      html;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param script_filename $document_root$fastcgi_script_name;
      include    fastcgi_params;
    }

改為

#
location ~ \.php$ {
      root      /home/fuxiao/www;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param script_filename $document_root$fastcgi_script_name;
      include    fastcgi_params;
    }

然後重新啟動nginx,網站根目錄就已經是我們的家目錄下的www。

二、解決403錯誤

但更改完成後進行測試,造訪www下的網頁一直提示403 forbidden,如下圖

Nginx網站根目錄更改導致403怎麼解決

#解決方法

開始以為是自己存取的網頁不具有讀取權限,於是給網頁授予了讀取權限,但更改後再次訪問依舊是該錯誤,試了多種方法後發現問題出在/home/fuxiao目錄的fuxiao不具備讀取權限,即我們普通用戶起初不具備讀取權限,只需給該目錄賦予讀取權限即可解決該403問題。

以上是Nginx網站根目錄更改導致403怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除