How to enable pathinfo in nginx

WBOY
Release: 2023-05-26 10:43:13
forward
1223 people have browsed it

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; 
}
Copy after login

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; 
}
Copy after login

这块要注意,location后正则要根据重写的url来决定。

The above is the detailed content of How to enable pathinfo in nginx. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template