Nginx重新路由代理响应
我想知道是否可以用nginx实现以下场景:Nginx重新路由代理响应,nginx,lua,Nginx,Lua,我想知道是否可以用nginx实现以下场景: 接受post请求(文件上载)并代理将其传递给某个后端服务器“a” 从代理服务器“A”获取响应,并将其发布到另一个后端服务器“B” 最后从服务器“B”获取响应并将其发送到客户端 我想我不能用nginx-ootb实现,但是lua脚本可以做到吗 (如果您想知道我们试图实现什么:客户端将文件发布到我们的FE服务器(nginx),该服务器只将文件发送到文件服务器(服务器“a”),那么我们需要获取文件服务器响应,并通过另一个服务器“B”运行它,从而为用户构建一个良
Thx.使用Nginx反向代理服务器是不可能的
您可以从服务器A调用服务器B,使用web服务解析响应。因此,使用nginx lua模块,我想到了以下方法:
location /upload {
lua_need_request_body on;
set $upres "";
rewrite_by_lua '
local res = ngx.location.capture("/doupload", {method = ngx.HTTP_POST, always_forward_body = true })
ngx.var.upres = res.body
';
content_by_lua '
local res = ngx.location.capture("/afterupload", { method = ngx.HTTP_POST, body = ngx.var.upres })
if res.status == 200 then
ngx.print(res.body)
end
';
}
location /doupload {
proxy_pass http://ServerA;
}
location /afterupload {
proxy_pass http://ServerB;
}