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问题。