Nginx + php-fpm 开启 PATH_INFO 模式

很多框架默认路由都是 PATH_INFO 模式,比如默认在 Apache 并且没有 rewrite 时,CodeIgniter 一般可以这样访问 /index.php/controller/action ,那么 nginx 和 php-fpm 如何设置支持 PATH_INFO 模式呢?

php.ini 中一个与 PATH_INFO 有关的设置是 cgi.fix_path 默认为 1,我们将其设置为 0。

php.ini 设置:

cgi.fix_path = 0

接下来是 nginx 配置:

01

location ~ \.php($|/) {

02

 

03

    # 下面这一行设置 $fastcgi_script_name 和 $fastcgi_path_info 的值,具体请看 nginx 文档

04

    fastcgi_split_path_info ^(.+\.php)(/.+)$;

05

     

06

    # 下面这行也可以为 fastcgi_pass unix:/var/run/php-fpm.sock 看你的 fpm 设置了

07

    fastcgi_pass   127.0.0.1:9000;

08

    fastcgi_index  index.php;

09

    include        fastcgi_params;

10

     

11

    # 下面这行不能少,默认 fastcgi_params 里面并没有 SCRIPT_FILENAME

12

    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

13

    fastcgi_param  PATH_INFO          $fastcgi_path_info;

14

}

 

 

参考:

http://wiki.nginx.org/HttpFastcgiModule

http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_split_path_info

http://www.php.net/manual/zh/ini.core.php#ini.cgi.fix-pathinfo

http://www.laruence.com/2009/11/13/1138.html

http://www.laruence.com/2010/05/20/1495.html


转载于:https://my.oschina.net/yonghan/blog/525114

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值