大叔经验分享(77)openresty(nginx+lua)发http请求

openresty(nginx+lua)发http请求

利用location+proxy_pass间接实现

    location ^~ /test/http {
        internal;
        proxy_pass http://test.com/path;
    }

lua代码

local res, err = ngx.location.capture("/test/http", {
    method = ngx.HTTP_POST,
    body = body
});
if res then
  ngx.log(ngx.INFO, "response:"..res.body)
else
  ngx.log(ngx.INFO, "error:"..err)
end

 

posted @ 2019-07-29 20:36  匠人先生  阅读(1394)  评论(0编辑  收藏  举报