nginx模式默认是不支持pathinfo模式的,类似index.php/index形式的url会被提示找不到页面。下面的通过正则找出实际文件路径和pathinfo部分的方法,让nginx支持pathinfo。

本文基于安装lnmp一键安装包,添加虚拟主机情况下进行修改。如你要添加一个网站www.支持pathinfo,配置文件nginx.conf不用任何改变,参考lnmp一键安装包
cat vhost/www..conf
- server{
- listen80;
- server_namewww.;
- access_loglogs/www..logcombined;
- root/home/wwwroot/www.;
- error_page404/404.html;
- indexindex.htmlindex.htmindex.php;
- location/{
- indexindex.php;
- if(!-e$request_filename){
- rewrite^/(.*)$/index.php/$1last;
- break;
- }
- }
- location~\.php{
- fastcgi_pass127.0.0.1:9000;
- fastcgi_indexindex.php;
- includefcgi_pathinfo.conf;
- set$real_script_name$fastcgi_script_name;
- if($fastcgi_script_name~“^(.+?\.php)(/.+)$”){
- set$real_script_name$1;
- set$path_info$2;
- }
- fastcgi_paramSCRIPT_FILENAME$document_root$real_script_name;
- fastcgi_paramSCRIPT_NAME$real_script_name;
- fastcgi_paramPATH_INFO$path_info;
- }
- }