工作,学习,生活,这里将会有一些记录. 备用域名:http://meisw.wdlinux.cn 注册 | 登陆

配置Nginx支持pathinfo模式

让Nginx支持pathinfo

Nginx服务器默认不支持pathinfo, 在需要pathinfo支持的程序中(如thinkphp),则无法支持”/index.php/Home/Index/index”这种网址.

网上流传的解决办法很多,这里提供一种比较简洁的写法(只需要改动2行代码)

典型配置

location ~ \.php$ {     root           html;     fastcgi_pass   127.0.0.1:9000;     fastcgi_index  index.php;     fastcgi_param  SCRIPT_FILENAME  $DOCUMENT_ROOT$fastcgi_script_name;     include        fastcgi_params; }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

修改第1,6行,支持pathinfo

location ~ \.php(.*)$ { # 正则匹配.php后的pathinfo部分     root html;     fastcgi_pass   127.0.0.1:9000;     fastcgi_index  index.php;     fastcgi_param  SCRIPT_FILENAME  $DOCUMENT_ROOT$fastcgi_script_name;     fastcgi_param PATH_INFO $1; # 把pathinfo部分赋给PATH_INFO变量     include        fastcgi_params; }
 
----------
location ~ .php {
  root "E:\www\wwwroot";
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  include fastcgi_params; 
  #pathinfo support 
  set $real_script_name $fastcgi_script_name;
  set $path_info ””;
  if ( $fastcgi_script_name ~ "^(.+?.php)(/.+)$"){
  set $real_script_name $1;
  set $path_info $2;
  } 
  fastcgi_param SCRIPT_NAME $real_script_name;
  fastcgi_param PATH_INFO $path_info; 
}

---------------
  1. location ~ \.php {    #去掉$
  2.      root          H:/PHPServer/WWW;
  3.      fastcgi_pass   127.0.0.1:9000;
  4.      fastcgi_index  index.php;
  5.      fastcgi_split_path_info ^(.+\.php)(.*)$;     #增加这一句
  6.      fastcgi_param PATH_INFO $fastcgi_path_info;    #增加这一句
  7.      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  8.      include        fastcgi_params;
  9. }
 
 
 

« 上一篇 | 下一篇 »

Trackbacks

点击获得Trackback地址,Encode: UTF-8

发表评论

评论内容 (必填):