2015-07-10 67 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; 
}