nginx怎么開啟pathinfo

apache往nginx去轉,代碼端用到了$_server[‘path_info’],對于nginx默認是不開啟pathinfo的。所以我們就要手動開啟

1,url重寫

location?/?{??//方法1? ?if?(!-e?$request_filename)? ?{? ?rewrite?^/(.*)$?/index.php/$1?last;? ?break;? ?}? }?? location?/?{??//方法2? ?try_files?$uri?$uri/?/index.php$uri;? }

2,pathinfo設置

location?~?.*.(php|php5)(.*)?$?//注意這塊,配置重寫的url? {? ?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?path_translated?$document_root$fastcgi_path_info;? ?include?fastcgi.conf;? }

這塊要注意,location后正則要根據重寫的url來決定。

? 版權聲明
THE END
喜歡就支持一下吧
點贊10 分享