配置Nginx环境实现支持pathinfo模式路径功能方法
前言:现在很多CMS程序或者特定的环境需要用到支持pathinfo模式路径功能,例如ThinkPHP、DUXCMS、typecho等,比如最近我们这边上线的一个网站程序在伪静态路径的时候需要支持类似http://localhost/index.php/news/22.html这样的格式效果,默认情况下Nginx是没有开启PATHINFO模式的,下面我们来说说针对这种情况PHP开启Pathinfo以及Nginx配置Pathinfo模式的方法:
PHP开启Pathinfo(PHP默认已经开启Pathinfo,如果没有开启按以下方法开启)
[root@localhost ~]# vi /etc/php.ini cgi.fix_pathinfo=1 [root@localhost ~]# service php-fpm reload
Nginx配置Pathinfo模式
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ \.php(.*)$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
includefastcgi_params;
}
}#上面关键在于以下三个点用于匹配http://localhost/index.php/news/22.html这样的Pathinfo路径
~ \.php(.*)$ fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info;
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。

这个有点牛B的感觉