看到火丁的博客裏的一篇文章,try_file和fastcgi_split_path_info的問題想了好久,一通googlephp
問題的描述在這裏,爲何會用這種問題呢;最後仍是在鳥哥的博客裏看到了。html
try_files有一個本身專門的工做階段,並且它還會重置$fastcgi_script_name 和 $fastcgi_path_infonginx
The try_files directive changes URI of a request to the one matched on the file system, and subsequent attempt to split the URI into $fastcgi_script_name and $fastcgi_path_info results in empty path info - as there is no path info in the URI after try_files.google
根據這個推測fastcgi_split_path_info應該是工做在try_files階段以前的,被後來的try_files指令覆蓋了,具體是工做在那個階段,暫時沒查到。unix
那這個問題怎麼解決呢,就是新加一個變量保存下$fastcgi_path_info的值htm
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
# Save the $fastcgi_path_info before try_files clear it
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
try_files $fastcgi_script_name =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}blog