技术文档

配置nginx,支持php的pathinfo路径模式

nginx模式默认是不支持pathinfo模式的,类似index.php/index形式的url会被提示找不到页面。下面的通过正则找出实际文件路径和pathinfo部分的方法,让nginx支持pathinfo。

配置nginx,支持php的pathinfo路径模式

本文基于安装lnmp一键安装包,添加虚拟主机情况下进行修改。如你要添加一个网站www.支持pathinfo,配置文件nginx.conf不用任何改变,参考lnmp一键安装包

cat vhost/www..conf

  1. server{
  2. listen80;
  3. server_namewww.;
  4. access_loglogs/www..logcombined;
  5. root/home/wwwroot/www.;
  6. error_page404/404.html;
  7. indexindex.htmlindex.htmindex.php;
  8. location/{
  9. indexindex.php;
  10. if(!-e$request_filename){
  11. rewrite^/(.*)$/index.php/$1last;
  12. break;
  13. }
  14. }
  15. location~\.php{
  16. fastcgi_pass127.0.0.1:9000;
  17. fastcgi_indexindex.php;
  18. includefcgi_pathinfo.conf;
  19. set$real_script_name$fastcgi_script_name;
  20. if($fastcgi_script_name~“^(.+?\.php)(/.+)$”){
  21. set$real_script_name$1;
  22. set$path_info$2;
  23. }
  24. fastcgi_paramSCRIPT_FILENAME$document_root$real_script_name;
  25. fastcgi_paramSCRIPT_NAME$real_script_name;
  26. fastcgi_paramPATH_INFO$path_info;
  27. }
  28. }
©2020-2024   万云SSL证书  (www.sslssl.com.cn)  万云科技   豫ICP备2020034358号-10