Nginx在使用try_files时不parsingphp

我基本上是试图实现Apache MultiViews行为,以便我的URL不需要.php扩展名。

就我从其他问题上看到的服务器故障回答,我应该有这个问题sorting,但是在我的nginxconfiguration中显然是错误的。

行为几乎是正确的;

  • 我可以浏览到/path/to/app/和index.php文件被正确parsing
  • 我可以浏览到/path/to/app/function.php文件被正确parsing
  • 我可以浏览到/path/to/app/media/some.jpg并将其作为静态内容提供
  • 如果我浏览到/path/that/doesnt/exist我得到一个404预期

但是,如果我浏览到/path/to/function try_files指令正确地匹配它到function.php但下载它作为一个静态文件。

这里是configuration文件:

 server { listen 80; server_name app; root /path/to/app; index index.php index.html index.htm; access_log /var/log/nginx/access.log; location / { allow all; try_files $uri $uri/ $uri.php =404; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; } location ~ /\.ht { deny all; } } 

看起来我只是误解了try_files的工作方式; =404是不需要的,并导致nginx不parsing文件为php一旦匹配。 删除它,使行只是try_files $uri $uri/ $uri.php; 解决了这个问题