使没有扩展名的文件通过nginx上的PHPparsing器

由于遗留的原因,我需要得到下面的情况在nginx上工作,我似乎在挣扎。 假设我在文件根目录中有一个名为'info'的文件,没有任何文件扩展名。 现在这是一个PHP文件,但它没有扩展名,并且因为我不会在这里解释的原因而不能重命名。 我将如何编写一个nginxconfiguration文件来parsingPHP文件。

我实际上已经尝试将这个文件重命名为info.php,然后将以下内容添加到我的nginxconfiguration中,然后尝试打击http://{siteurl}/info期望它在内部重写到info.php ,但所有做到了index.html

 location / { try_files @extensionless-php $uri $uri/ /index.html; } location @extensionless-php { rewrite ^(.*)$ $1.php last; } 

现在我对nginx很陌生,所以我认为我只是缺less一些非常基本的东西。 以前在Apache的configuration是这样的,让这种情况下工作…

  <LocationMatch "^/(info|...a few other files...)/?.*$"> ForceType application/x-httpd-php </LocationMatch> 

任何帮助深表感谢。

尝试这个。 注意我的try_files是你的例子中的一个小小的重新洗牌。 另外我添加了root ,这应该匹配您的网站根path。

 location / { root /your/web/root/path try_files $uri $uri/ @extensionless-php; index index.php index.html; } location @extensionless-php { rewrite ^(.*)$ $1.php last; } 

终于搞明白了:

 location /info { root /usr/share/nginx/www; fastcgi_pass unix:/var/run/php5-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/www/info.php; } 

其实现在是有道理的,因为我一直懒得读文档…

这对我来说是有效的:

 ## Your root already needs to be defined # root /your/web/root/path location / { try_files $uri $uri/ $uri.php =404; index index.php index.html; } 

在打一个url( http://somedomain.com/some/path/action )这个会首先尝试some/path/action ,然后是some/path/action/[index.php] ,然后是some/path/action.php如果无法find该文件,则会失败。