这里比较兼容的处理是:
server { listen 80; server_name 域名; root 路径; if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } access_log /var/log/nginx/域名-access.log; error_log /var/log/nginx/域名-error.log; location / { index index.php; } location ~ .php { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_read_timeout 60s; fastcgi_split_path_info ^((?U).+.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } }
这里是非贪婪模式:
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
(?U)表示对后面的子串进行非贪婪匹配
fastcgi_split_path_info ^(.+.php)(/.*)$; 这种是贪婪匹配,具体区别看下图
非贪婪下,只匹配到第一个.php
贪婪下匹配到最后一个.php