nginx版本:1.2.1 codeigniter:2.1.2
nginx需要增加以下:
location ~ \.php {
root ;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_index index.php;
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 PATH_INFO $path_info;
fastcgi_param SCRIPT_NAME $real_script_name;
#fastcgi_param SCRIPT_FILENAME $real_script_name;
#fastcgi_param REQUEST_URI $real_script_name;
}
注意:
1.是~\.php而不是~\.php$
2.include fastcgi_params需要放在特殊设置的变量之前
linux环境:
location ~ \.php($|/) {
root /home/leo/workspace;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
}
说明:codeigniter内部是根据SCRIPT_NAME和REQUEST_URI来识别controller和method的。
具体是根据REQUEST_URI-SCRIPTNAME,剩下的字符串作为directory/class/method的各个字段,以‘/’分割,
所以我们需要设置REQUEST_URI和SCRIPT_NAME
上述代码片段是将url中的.php之前的作为SCRIPT_NAME,整个作为REQUEST_URI,
这样codeigniter就可以正常识别了。