Nginx网站根目录更改导致403怎么解决
作者:小确幸
时间:2024-03-31
浏览:0
一、更改根目录nginx默认网站根目录为/usr/local/nginx/html,要将它改成/home/fuxiao/www更改方法:vi/usr/local/nginx/conf/nginx.conf将其中的location/{roothtml;indexindex.phpindex.htmlindex.htm;}改为location/{root/home/fuxiao/www;indexindex.phpindex.htmlindex.htm;}然后再将location~\.php${roothtm
一、更改根目录
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,如下图

解决方法
开始以为是自己访问的网页不具有读权限,于是给网页授予了读权限,但更改后再次访问依旧是该错误,试了多种方法后发现问题出在/home/fuxiao目录的fuxiao不具备读权限,即我们普通用户起初不具备读权限,只需给该目录赋予读权限即可解决该403问题。
作者最新文章
Windows 10
2026-09-16 17:44
Python安装后怎么打开:使用IDLE或命令行启动解释器
2026-09-16 13:54
Windows系统Python安装教程:下载、勾选PATH及环境变量配置
2026-09-16 13:53
“等灯不计时”落地解析:算法善意如何转化为技术能力与生态协同
2026-09-08 18:03
英伟达推出NVHBM:定制HBM带宽提升30%并扩展NVLink Fusion生态
2026-09-08 17:31
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多

































