Nginx不通过重写到PHP-FPM

我有以下重写nginx的规则。

规则似乎无法正常工作,例如游戏规则应该将http://thegamesdb.net/game/2/重写为http://thegamesdb.net/index.php?tab=game?id=2当我导航到/游戏/ 2 /浏览器正在下载一个名为简单download的文件hover。

我的重写规则如下:

 # nginx configuration location /game { rewrite ^/game/([0-9]+)(/?)$ /index.php?tab=game&id=$1 break; rewrite ^/game-edit/([0-9]+)(/?)$ /index.php?tab=game-edit&id=$1 break; } location /search { rewrite ^/search/([a-z0-9\-\ /\+]+)(/?)$ index.php?tab=listseries&string=$1&function=Search break; rewrite ^/search(/?)$ /index.php?tab=listseries&function=Search break; } location /browse { rewrite ^/browse/([0-9+]*)(/?)$ /index.php?tab=listplatform&stringPlatform=$1&function=Browse+By+Platform break; } location /platform { rewrite ^/platform/([0-9]+)(/?)$ /index.php?tab=platform&id=$1 break; rewrite ^/platform/([a-z0-9\-]+)(/?)$ /index.php?tab=platform&alias=$1 break; rewrite ^/platform-edit/([0-9]+)(/?)$ /index.php?tab=platform-edit&id=$1 break; } location /favorites { rewrite ^/favorites(/?)$ /index.php?tab=favorites break; } location /message { rewrite ^/message/([0-9]+)(/?)$ /index.php?tab=message&messageid=$1 break; } location /adminstats { rewrite ^/adminstats/([a-z0-9\-]+)(/?)$ /index.php?tab=adminstats&statstype=$1 break; } location /blog { rewrite ^/blog(/?)$ /blog/ break; } location /wiki { rewrite ^/wiki(/?)$ /wiki/ break; } location /forums { rewrite ^/forums(/?)$ /forums/ break; } location /phpmyadmin { rewrite ^/phpmyadmin(/?)$ /phpmyadmin/ break; } location / { rewrite ^/([a-z0-9\-\ /\+]+)(/?)$ index.php?tab=$1 break; if (!-e $request_filename){ rewrite ^(.*)$ /index.php break; } } 

我看不出规则有什么问题,我错过了什么?

顺便说一句,我使用的是Ajenti-V,上面的规则被join到Ajenti-V网站的定制configuration面板中。

更新:

似乎我现在的重写规则需要通过路由到php-fpm因为它们当前仅被视为一个静态文件。

我将如何适应上面的代码来完成这个?

你没有位置块转发请求的PHP文件处理后端。

添加一个PHP文件的位置块,并使用nginx fastcgi_module ,然后转换重写为php文件从breaklast

您可以在服务器故障中find很多示例: search

更新 :根据注释中的问题修复根位置块。

你的正则expression式已经匹配/ so /? 永远不会匹配任何东西,例如/stats/ 。 你必须设置两个重写规则:

 location / { rewrite "^/(.*)/$" /$1; rewrite "^/([- +a-z0-9/]+)$" /index.php?tab=$1 last; [ ... ] }