我正在尝试使用lua-resty-http模块代理请求。我目前正在为http请求传递头部,主体,请求方法和url,这工作得很好。但当文件上传post请求到来时,它无法这样做,显然我还没有配置它来这样做。所以我也想要代理那种类型的请求。下面是我到目前为止代码的一小部分,我应该做哪些更改,以便它提取文件上传数据并使用lua-resty-http模块->发送它
local http = require "resty.http"
local cjson = require "cjson"
local httpc = http.new()
local path = ngx.var.request_uri
local passHeader = {["cookie"]=ngx.req.get_headers()["cookie"]}
passHeader["content-type"] = ngx.req.get_headers()["content-type"]
ngx.req.read_body();
body = ngx.req.get_body_data();
local original_req_uri = "https://" .. "fakehost.com" .. path
local req_method = ngx.req.get_method()
local res, err = httpc:request_uri(original_req_uri, {
method = req_method,
ssl_verify = false,
keepalive_timeout = 60000,
headers = passHeader,
keepalive_pool = 10,
body = body
})发布于 2021-03-09 14:38:04
阅读文档!
https://github.com/openresty/lua-nginx-module#ngxreqget_body_data
POST请求可能包含较大的主体,nginx可能会将其写入磁盘文件。
如果请求正文已被读入磁盘文件,请尝试调用ngx.req.get_body_file函数。
PS: Lua代理HTTP请求的IMO方法不是最优的,因为它是全缓冲的方式。对我来说,只有当我们需要发出一个子请求时,它才有意义。对于处理大多数请求的主路径,我建议使用proxy_pass。
https://stackoverflow.com/questions/66528948
复制相似问题