nginx 403 forbidden

nginx报错,首先查看nginx的日志。一般在nginx的logs的目录下。

nginx出现403,不一定是权限问题,可能是缺少index文件,或者是缺少入口文件的配置。

1. directory index of "/usr/share/nginx/html/" is forbidden

1.1 如果在/usr/share/nginx/html下面没有index.php,index.html的时候,直接访问域名,找不到文件,会报403 forbidden。

解决办法:添加文件即可

1.2 还有一个原因就是你的默认的nginx配置文件的location没有指定root路径,我的就是这个问题。

这个就直接在默认的server上面加上:

location / {
    root html;
    index index.php index.html index.htm;
}
原文地址:https://www.cnblogs.com/mengff/p/13265486.html