403使用nginx禁止wordpress索引,其余页面工作正常

时间:2013-08-07 18:58:21

标签: wordpress nginx http-status-code-403

我正在新的EC2实例上设置我的博客,因为当前托管它的服务器上的一个站点是DDoSed。 我在使用nginx时遇到了一些麻烦,因为我可以看到所有页面都很好但是索引上有403,或者看到索引但页面上有404(取决于我使用的配置)

这是我的nginx配置:

server {
    listen       80;

    server_name  www.test.com;
    server_name  test.com;
    root /www/blog;

    include conf.d/wordpress/simple.conf;
}

而simple.conf:

location = /favicon.ico {
            log_not_found off;
            access_log off;
    }

    location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
    }

    location / {
            # This is cool because no php is touched for static content. 
            # include the "?$args" part so non-default permalinks doesn't break when using query string
            try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
            #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            include fastcgi.conf;
            fastcgi_intercept_errors on;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
            log_not_found off;
    }

如果我更改了try_files $ uri $ uri / /index.php?$args;索引index.php ,首页将正常工作,其余的将是404.如果我这样做,首页是403.

这是错误日志:

2013/08/07 19:19:41 [error] 25333#0: *1 directory index of "/www/blog/" is forbidden, client: 64.129.X.X, server: test.com, request: "GET / HTTP/1.1", host: "www.test.com"

nginx用户的目录是755:

drwxr-xr-x 6 nginx nginx  4096 Aug  7 18:42 blog

有什么明显的我做错了吗?

谢谢!

3 个答案:

答案 0 :(得分:18)

添加index index.php;在服务器区中,如果它不起作用,则您需要删除$uri/,因为您不想执行autoindex on < / p>


编辑:刚刚注意到您已经发现了问题,所以我会在其背后添加推理,这就是您需要的原因{{1因为没有它,nginx将遵循autoindex on;规则,

  1. 检查是否有名为try_files的文件,当然是失败。
  2. 检查是否有名为/的目录(通过添加root = /),此检查将成功,因此它会尝试列出文件夹的内容。
  3. 由于你没有指定/www/blog/所以默认情况下nginx应该禁止目录列表,因此会返回403禁止错误。
  4. 网站的其余部分工作正常,因为它未通过autoindex on;测试或无法覆盖,因为您可能没有名为$uri/或{{1}的文件夹等等。

答案 1 :(得分:1)

看起来我需要服务器{}定义中的索引index.php而不是位置{}

答案 2 :(得分:0)

您似乎不允许将参数发送到CMS,因此这不会显示此uris会从数据库中提取信息并将您重定向到403页面。