nginx支持pathinfo和url重写(摘自燕十八)

# 典型配置
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,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;
}
注意同时还需要url重写
location / {
  root html/abc/public;
  index index.php index.html;
  if ( !-e $request_filename ){
    rewrite (.*)$ /index.php/$1;
  }
}
posted @ 2019-11-14 13:02  $DeBuger  阅读(183)  评论(0)    收藏  举报