Thinkphp在Nginx下开发因找不到文件报错的解决方法(伪静态规则)
作者:我就是个世界
发表于:2012-11-16
Thinkphp在Nginx下开发,总是提示404的错误,原因是apache默认支持Thinkphp等所需的PATH_INFO,而nginx不可以,那么接下来,我们就配置一下nginx,让他支持PATH_INFO:
主要是修改Nginx配置的location部分[separator]
默认是这样的:
[code]
location ~ .*\.php?$ {
root F:\dev\feeling;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME F:\dev\feeling$fastcgi_script_name;
include fastcgi_params;
}
[/code]
修改为这样即可:
[code]
location ~ .*\.php/?.*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#以下是针对THINKPHP 让Nginx支持PATH_INFO
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME F:\CZfeeling\feeling$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include fastcgi_params;
}
[/code]
主要是修改Nginx配置的location部分[separator]
默认是这样的:
[code]
location ~ .*\.php?$ {
root F:\dev\feeling;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME F:\dev\feeling$fastcgi_script_name;
include fastcgi_params;
}
[/code]
修改为这样即可:
[code]
location ~ .*\.php/?.*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#以下是针对THINKPHP 让Nginx支持PATH_INFO
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME F:\CZfeeling\feeling$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include fastcgi_params;
}
[/code]
请发表您的评论