更改Nginx網站根目錄以及致使的403 forbidden問題解決

版權聲明:本文爲博主原創文章,未經博主容許不得轉載。

1、更改根目錄php

 

Nginx默認網站根目錄爲/usr/local/nginx/html,要將它改爲/home/fuxiao/wwwhtml

 
更改方法:
 
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。
 
2、解決403錯誤
 
但更改完成後進行測試,訪問www下的網頁一直提示403 forbidden,以下圖
 
開始覺得是本身訪問的網頁不具備讀權限,因而給網頁授予了讀權限,但更改後再次訪問依舊是該錯誤,試了多種方法後發現問題出在/home/fuxiao目錄的fuxiao不具有讀權限,即咱們普通用戶起初不具有讀權限,只需給該目錄賦予讀權限便可解決該403問題。
相關文章
相關標籤/搜索