2015-07-10 42 views
0

我不知道我是否可以与nginx的实施以下情形:Nginx的重新路由代理响应

  1. 接受POST请求文件上传和代理将它传递给一些后端服务器“A”。
  2. 从代理服务器“A”获取响应并将其发布到另一个后端服务器“B”。
  3. 最后得到服务器“B”的响应并发送给客户端。

我想我不能用nginx做到这一点ootb,但可以做一个lua脚本吗? (如果你想知道我们试图实现的目标:客户端将文件发送到我们的FE服务器(nginx),该文件只是将文件发送到文件服务器(服务器“A”),那么我们需要将文件服务器响应并通过另一台服务器运行,“B”为用户提供了很好的响应)。

Thx。

回答

0

Nginx反向代理服务器无法实现。

您可以从服务器-A调用服务器-B以使用Web服务解析响应。

0

因此,使用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; 
}