1.解决.php后面加各种控制时出错,(如访问http://laeni/index.php/index/index/index时,nginx会去"/index.php/index/index/index"目录找导致出错)
location ~ \.php {
root $root;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
set $script $uri;
set $path_info "";
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
set $path_info $2;
}
#fastcgi_index index.php?IF_REWRITE=1;
fastcgi_index index.php;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_NAME $script;
include fastcgi_params;
}2.解决url中省略".php"时Nginx值当做静态资源解析出错(1),首先更改配置nginx网站根目录,将 "原来网站根目录/项目名/public"设置为网站的根目录,因为新版thinkphp的入口文件在public目录中
(2)更改nginx配置
location / {
root $root;
index index.php index.html index.htm;
#下面主要是解决在url地址中省略"index.php"时使用的规则
if ( -f $request_filename) {
break;
}
#如果请求既不是一个文件,也不是一个目录,则执行一下重写规则
if ( !-e $request_filename) {
#地址作为将参数rewrite到index.php上
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
} 最佳答案