是否可以合并多个响应并在 NGINX 中发送一个响应
Is it possible to consolidate multiple responses and send one response in NGINX
我在一台虚拟机上有 Nginx/openresty 和一些其他服务 运行。基本上 VM 接受 Openresty 上的请求,然后 openresty 将请求转发到适当的服务。例如下面的请求分别转发到 ServiceA、ServiceB 和 ServiceC。它工作正常。
现在我需要公开一个新端点,它可以从所有服务 A、B 和 C 获得响应,然后 return 一个综合响应。
我不能在我的位置使用多个 proxy_pass,有人可以建议我如何实现吗?例如
http://server:80/services/refALL --> return来自 A、B 和 C 服务的综合响应。
你可以像下面那样做。基本上你捕获来自其他服务的响应,然后将它们组合起来
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)
}
}
我在一台虚拟机上有 Nginx/openresty 和一些其他服务 运行。基本上 VM 接受 Openresty 上的请求,然后 openresty 将请求转发到适当的服务。例如下面的请求分别转发到 ServiceA、ServiceB 和 ServiceC。它工作正常。
现在我需要公开一个新端点,它可以从所有服务 A、B 和 C 获得响应,然后 return 一个综合响应。
我不能在我的位置使用多个 proxy_pass,有人可以建议我如何实现吗?例如
http://server:80/services/refALL --> return来自 A、B 和 C 服务的综合响应。
你可以像下面那样做。基本上你捕获来自其他服务的响应,然后将它们组合起来
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)
}
}