nginx 开启 pathinfo

前端之家收集整理的这篇文章主要介绍了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来决定。

原文链接:https://www.f2er.com/nginx/447339.html

猜你在找的Nginx相关文章