Nginx位置匹配中带括号的变量捕获

Variable capture with parenthesis in Nginx location matching

我有这个定位规则:

location ~ ^/banks/(?P<region>[\w/~\-]+?)/responses/?$ {
    rewrite ^ $scheme://${host}/services/responses/list/city/${region}/? permanent;
}

它非常适合 url 像 :

http://example.com/banks/Arhangel~skaya_oblast~/Mirnyiy/responses/

但现在我需要修改我的位置以匹配其中带有括号的 urls。我用的是这个版本:

location ~ ^/banks/(?P<region>[\w/~\-()]+?)/responses/?$ {
    rewrite ^ $scheme://${host}/services/responses/list/city/${region}/? permanent;
}

但是url/banks/Respublika_Saha_(Yakutiya)/Neryungri/responses/没有重写。

我用 php preg_match 函数检查这个模式:

preg_match('|^/banks/(?P<region>[\w/~\-()]+?)/responses/?$|',
    '/banks/Respublika_Saha_(Yakutiya)/Neryungri/responses/');

它 returns 1,所以这个模式匹配 url 与 ().

此外,我用 python re.search:

检查这个字符串
import re
matches = re.search('|^/banks/(?P<region>[\w/~\-()]+?)/responses/?$|','/banks/Respublika_Saha_(Yakutiya)/Neryungri/responses/')
print matches.start()

而它returns0,所以这个模式从头开始匹配这个字符串。

但是nginx不这么认为

我应该如何修改 nginx 位置规则以匹配此 url /banks/Respublika_Saha_(Yakutiya)/Neryungri/responses/

P.S。我的 nginx 版本是 nginx/1.9.10

抱歉这个问题。 Nginx 完美运行。问题不在于 nginx,而在于我们的 devops(几乎没有开发和非常糟糕的操作)。下面我添加我们系统的方案。简而言之,该系统由以下部分组成:nginx 平衡器、apache 遗留系统、用于基于 soa 的新系统的 nginx、用于服务的 nginxes。

我咨询了 devops,他们告诉我更改我们 git 存储库之一中的某些 nginx 配置。我改变了它,记住平衡器配置,但我们的开发人员忘记了 nginx 平衡器,因为它不受版本控制。所以我已经为新的 SOA 系统更改了 nginx 配置,但是这个重定向应该在平衡器阶段将我们的用户从旧系统发送到新系统。

我对我们的 devops 感到非常沮丧,所以 Nginx 可以工作,但他们不能:)