通常我们在配置nginx使其支持php时,都是进行类似如下配置:
location ~ .php$ {
root /var/www/bbs.dingd.cn;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
(反正我每次都偷懒,复制粘贴来就使用)
上述配置正常使用起来没什么问题,但是一旦遇到这样的url,就炸了:
/index.php/content/123.html
因为配置中是将以.php结尾的文件交给php-fpm处理,那么这样的url结尾就是.html所以肯定返回404啦。而且,php也是获取不到php_info这个值得。
so,经常半天的百度啊 百度,终于找到如下配置,可以正常使用(我稍微改动了一下)
location ~ (\.php)(.*)$ {
root /var/www/bbs.dingd.cn;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
#PHP中要能读取到pathinfo这个变量
#就要通过fastcgi_param指令将fastcgi_split_path_info指令匹配到的pathinfo部分赋值给PATH_INFO
#这样PHP中$_SERVER['PATH_INFO']才会存在值
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}