nginx 开启 pathinfo的过程详解

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

nginx 开启 pathinfo的过程详解

  2021-04-03 我要评论

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来决定。

您可能感兴趣的文章:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们