是否可以重写从 GCP 负载均衡器到后端服务(例如 Cloud Run)的传入请求?

发布于 2025-01-19 20:29:42 字数 1129 浏览 7 评论 0原文

我有两个运行云运行的服务,例如api1api2

我在GCP中设置了一个全局外部HTTP(S)加载平衡器(经典),以路由通往两种服务的路径。

例如

路径操作后端
/api1/*将流量路由到单个后端服务-API1
/api2/*将流量路由到单个后端服务-API2。

当我发送请求myDomain/api1/aaa/ccc/ mydomain/aaa/aaa/ccc/code>获取请求URL为

>,api1在我发送请求myDomain/api2/ddd/eee/时, ,api2获取请求URL作为myDomain/api2/ddd/eee/

是否有办法重写api1的传入请求,以便api1会将请求视为mydomain/aaa/ccc/

这也适用于api2,因此api2将从

重写文档

负载平衡器提供以下相互排斥的初级 动作:

  • 在请求中读取传入的URL。
  • 替换主机,路径或主机和路径,在将流量引向后端服务之前将URL转换为 或后端桶。

我认为有一种方法,但我无法使它起作用。

有建议吗?

I have two services running Cloud Run such as api1 and api2.

I set up a global external HTTP(S) load balancer (classic) in GCP to route the path to both services.

such as

PathsActionBackend
/api1/*Route traffic to a single backendservice-api1
/api2/*Route traffic to a single backendservice-api2

When I send a request mydomain/api1/aaa/ccc/, api1 get the request url as mydomain/api1/aaa/ccc/

When I send a request mydomain/api2/ddd/eee/, api2 get the request url as mydomain/api2/ddd/eee/

Is there a way to rewrite the incoming request for api1, so that api1 will see the request as mydomain/aaa/ccc/?

This also apply to api2, so api2 will see the request as mydomain/ddd/eee/

From the Rewrite documentation,

The load balancer provides the following mutually exclusive primary
actions:

  • Reads the incoming URL in the request.
  • Replaces the host, the path, or both the host and the path, transforming the URL before directing traffic to the backend service
    or backend bucket.

I think there is a way, but I don't manage to make it work.

Any advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

横笛休吹塞上声 2025-01-26 20:29:42

在负载平衡控制台页面中,

  1. 选择高级主机和路径规则(URL重定向,RERL重写) in host> host and Path Rules

  1. ”如下(显示附加操作)编辑路径规则

当您发送请求myDomain/api1/aaa/ccc/ api1 将看到该请求为myDomain/aaa/aaa/ccc/code>。

In load balancing console page

  1. Select Advanced host and path rule (URL redirect, URL rewrite) in Host and path rules

enter image description here

  1. Add a path rule and edit path rule as below (show Add-On action)

enter image description here

  1. Save and update the changes.

When you send a request mydomain/api1/aaa/ccc/, api1 will see the request as mydomain/aaa/ccc/.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文