是否可以重写从 GCP 负载均衡器到后端服务(例如 Cloud Run)的传入请求?
我有两个运行云运行
的服务,例如api1
和api2
。
我在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
Paths | Action | Backend |
---|---|---|
/api1/* | Route traffic to a single backend | service-api1 |
/api2/* | Route traffic to a single backend | service-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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在负载平衡控制台页面中,
高级主机和路径规则(URL重定向,RERL重写)
inhost> host and Path Rules
当您发送请求
myDomain/api1/aaa/ccc/
api1 将看到该请求为myDomain/aaa/aaa/ccc/code>。
In load balancing console page
Advanced host and path rule (URL redirect, URL rewrite)
inHost and path rules
When you send a request
mydomain/api1/aaa/ccc/
,api1
will see the request asmydomain/aaa/ccc/
.