不少框架默認路由都是 PATH_INFO 模式,好比默認在 Apache 而且沒有 rewrite 時,CodeIgniter 通常能夠這樣訪問 /index.php/controller/action ,那麼 nginx 和 php-fpm 如何設置支持 PATH_INFO 模式呢?php
php.ini 中一個與 PATH_INFO 有關的設置是 cgi.fix_path 默認爲 1,咱們將其設置爲 0。html
php.ini 設置:nginx
cgi.fix_path = 0框架
接下來是 nginx 配置:php-fpm
01.net
location ~ \.php($|/) {unix
02htm
03ip
# 下面這一行設置 $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