根据 GCP 上的参数重定向请求

Redirect request based on parameter on GCP

我有一个小型演示应用程序,它是一个键值存储。我已将其上传到 GCP,我想知道是否可以将请求重定向到适当的分片。我想做的是这样的:

虽然 GCP 的负载均衡器有 URL 映射和路径规则,但它主要是基于端点的重定向。例如用于获取视频内容; v1/hd/{videoId} 将重定向到高清视频服务,v1/uhd/{videoId} 将重定向到超高清视频服务。就我而言,这不能解决我的问题。我希望 Load Balancer 检测参数的第一个字符,可能是像这样的正则表达式 ^([A-M]|[a-m]) 或类似的东西,如果参数以从 A 到 M 的字符开头,它应该重定向到服务 1.

这合理吗?如果可以,可以吗?

Url 映射路径匹配器 支持条件或正则表达式。

引自documentation,路径匹配器有一些限制:

A path rule can only include a wildcard character (*) after a forward slash character (/). For example, /videos/* and /videos/hd/* are valid for path rules, but /videos* and /videos/hd* are not.

Path rules do not use regular expression or substring matching. For example, path rules for either /videos/hd or /videos/hd/* do not apply to a URL with the path /video/hd-abcd. However, a path rule for /video/* does apply to that path.

Path matchers (and URL maps in general) do not offer features that function like Apache LocationMatch directives. If you have an application that generates dynamic URL paths that have a common prefix, such as /videos/hd-abcd and /videos/hd-pqrs, and you need to send requests made to those paths to different backend services, you might not be able to do that with a URL map. For simple cases containing only a few possible dynamic URLs, you might be able to create a path matcher with a limited set of path rules. For more complex cases, you need to do path-based regular expression matching on your backends.


可以通过将 NginxApache 网络服务器设置为 LoadBalancer 的唯一后端并将此后端配置为使用 [=26] 路由请求来实现您正在寻找的内容=]conditions and/or regex 到您的服务。

PS: If is Evil... when used in location context