使用 openresty nginx 配置捕获以特定值开头的位置

我正在使用 openresty,在我的 default.conf 文件中,我正在检查某些 API 是否为此 API 的请求,如果是,则需要按原样将请求发送到后端。我是这样做的:

location = /y/products/ {
  include /xxx/yyy/some.conf;
}

这很好用。然而,我希望能够对以 /y/products 开头的 API 调用执行类似的操作。

因此,假设我的 API 可能是以下内容:

y/products/00000001-2aef-13ef-b12f-8b7e4f3f4e1a/check?val=abcdefgh

如何更改上面的位置检查语法以捕获此类请求,以便我可以决定如何处理这些 API 调用?

点赞
用户9783845
用户9783845

移除等号:

location /y/products/ {
  ...
}

一个 location 可以通过前缀字符串或正则表达式来定义。

另外,使用“=”修饰符可以定义 URI 和 location 的精确匹配。

https://nginx.org/en/docs/http/ngx_http_core_module.html#location

2020-08-12 22:02:58