我正在一个新的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
有什么明显的我做错了吗?
谢谢 !
最佳答案
添加索引index.php;在服务器块中,如果它不起作用,那么你需要删除$uri /因为你不想做自动索引
编辑:刚刚注意到你已经找到了你的问题,所以我将添加它背后的推理,你需要自动索引的原因;是因为没有它,nginx将遵循try_files规则,
>检查是否有一个名为/的文件,当然它失败了.
>检查是否有一个名为/的目录(通过添加root将= / www / blog /),此检查将成功,因此它会尝试列出该文件夹的内容.
>由于您未指定autoindex;所以默认情况下nginx应该禁止目录列表,因此它会返回403禁止错误.
>网站的其余部分工作正常,因为它未通过$uri / test或未达到它,因为您可能没有名为image.jpg或stylesheet.css等的文件夹.