增加一个重写规则:
location / {
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}但是当php文件不存在时,死活提示 404,就是没有让 index.php 来处理。 怀疑nginx的rewrite是否没装上,测试N次,rewrite是起作用的。查资料,看到:
http://www.nginx.cn/300.html 对于wordpress 的nginx 规则跟网上其他的大不一样:
location / {
try_files $uri $uri/ /index.php?$args;
}突然注意到配置文件里有:
location ~ .*\.(php|php5)?$
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}在判断完 location / { 部分后,继续执行到这里,因为是 php 后缀,继续执行, try_files $uri =404; 生效,所以一直提示 404。改成
try_files $uri /index.php?$args;
就OK

1326

被折叠的 条评论
为什么被折叠?



