服务器 
首页 > 服务器 > 浏览文章

nginx 开启 pathinfo的过程详解

(编辑:jimmy 日期: 2024/6/3 浏览:3 次 )

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:Prometheus 整合 AlertManager的教程详解
下一篇:等保测评:Centos超时退出问题
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网