nginx访问php 403 Forbidden

搭完wordpress之后,访问
http://xxx.com/blog/index.php
网页报:403 Forbidden

搜了一圈,发现大多是权限问题,所以就先考虑把网站目录的Owner改一下

我是Ubuntu下直接apt-get的,先通过配置文件查一下nginx的user

head /etc/nginx/nginx.conf

看到是
user www-data;

进行chown
chown -R www-data: blog

重启nginx,重新访问
依旧是报403

看一下错误日志

vi /var/log/nginx/error.log

发现这么一段
2017/03/10 04:15:50 [error] 862#0: *1 directory index of "/usr/share/nginx/html/blog/" is forbidden, client: 119.129.123.9, server: localhost, request: "GET /blog/ HTTP/1.1"

想起我装完php之后没有修改nginx的sites-available
vi /etc/nginx/sites-available/default

在下面index的地方,加多一个index.php
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm index.php;


重启,搞定

Leave a Reply

Your email address will not be published. Required fields are marked *