nginx:正则表达式与 URI 不匹配

nginx:正则表达式与 URI 不匹配

我有此 URI/orls/myservice/f?p=4550和以下位置

location ~ "^/(.+)/myservice/f?p=(.+)$" {
 .....
}

nginx 返回 404 未找到。问题可能来自?所以我尝试了\?但仍然收到相同的错误。有人可以帮忙吗?

答案1

位置匹配不考虑查询字符串:

Note that locations of all types test only a URI part of request line 
without arguments. This is done because arguments in the query string 
may be given in several ways [...]

http://nginx.org/en/docs/http/request_processing.html

答案2

尝试逃离/特点

http://regexr.com/3apga

答案3

您需要转义斜杠和问号,如下所示:

location ~ "^\/(.+)\/myservice\/f\?p=(.+)$" {
 .....
}

这将匹配第一个文件夹和p arg。

1 = orls
2 = 4550

相关内容