nginx starts the pathinfo process

  • 2020-05-17 07:49:52
  • OfStack

apache goes to nginx, the code side USES $_SERVER['PATH_INFO'], pathinfo is not turned on for nginx by default. So we have to turn it on manually

1, url rewrite


location / {  // methods 1 
 if (!-e $request_filename) 
 { 
 rewrite ^/(.*)$ /index.php/$1 last; 
 break; 
 } 
}  
location / {  // methods 2 
 try_files $uri $uri/ /index.php$uri; 
} 

2, pathinfo Settings


location ~ .*\.(php|php5)(.*)?$ // Notice this, configuration override 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; 
}

Note here that after location the regex is determined according to the url rewrite.


Related articles: