403错误主要有以下3条原因:
1、对于PHP而言,如果nginx用户没有web目录的权限,则会导致该错误,解决办法:chown -R nginx_user:nginx_usergroup /path/to/your-document-root
(比如chown -R www:www /usr/local/nginx/html/ )
2、未设置index的类型,需要在nginx.conf中的index后面加上要访问的文件类型,例如:index index.html index.htm index.php;
3,更改完nginx.conf配置文件中以下的document_root的路径之后,发现访问网页会出现403 Forbidden。
location / { root html; index index.html index.htm index.php; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts $fastcgi_script_name ; fastcgi_param SCRIPT_FILENAME /path/to/your-document-root$fastcgi_script_name ; include fastcgi_params; } |
通过在nginx的logs目录下,使用tail -f * 查看错误信息.
很显然,是由于权限问题造成,所以需要更改document_root目录的权限,使用chmod命令:
chmod -R o+rx /path/to/your-document-root
然后,再次访问该网页,没有403 Forbidden了吧。
注意:运行chmod -R 777 /path/to/your-document-root是不够的,必须运行
chmod -R o+rx /path/to/your-document-root