商城首页欢迎来到中国正版软件门户

您的位置:首页 > 编程开发 >nginx怎么开启pathinfo

nginx怎么开启pathinfo

  发布于2025-04-15 阅读(0)

扫一扫,手机访问

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.yisu.com/zixun/578483.html 如有侵犯,请联系admin@zhengruan.com删除

热门关注