有可能在 NGINX 中合并多个响应并发送一个响应吗?

我在一台虚拟机上运行 Nginx/openresty 和其他一些服务。基本上 VM 在 Openresty 上接受请求,然后 openresty 将请求转发到适当的服务。例如,下面的请求分别转发到 ServiceA、ServiceB 和 ServiceC。它工作得很好。

现在我需要公开一个新的端点,它可以从所有服务 A、B 和 C 中获取响应。然后返回一个合并的响应。

我不能在我的位置中使用多个 proxy_pass,请问有人能建议我如何实现这个需求?例如

http://server:80/services/refALL --> 从 A、B 和 C 服务返回一个合并的响应。

点赞
用户2830850
用户2830850
你可以像下面这样做。基本上,您捕获其他服务的响应然后将它们组合在一起。

location /services/refALL { content_by_lua_block { local respA = ngx.location.capture("/services/refA") local respB = ngx.location.capture("/services/refB") local respC = ngx.location.capture("/services/refC")

  ngx.say(respA.body .. respB.body .. respC.body)

} }

```

2017-09-17 19:50:18