为什么在nginx服务中使用lua-resty-http 的set_keepalive不生效?

新手上路,请多包涵

在openresty 里面使用http.set_keepalive不生效,总是返回failed to set keepalive: closed while sending to client

location / {

    mirror /mirror1;
    resolver 192.168.36.10 valid=10s;
    proxy_pass  http://backends;
    proxy_method $request_method;
    mirror_request_body on;
    proxy_pass_request_body on;

    proxy_set_header Host $host:$server_port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Real-PORT $remote_port;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    content_by_lua_block {
        local http = require "resty.http"
        local ngx_log = ngx.log
        local ngx_ERR = ngx.ERR
        local httpc = http.new()
        httpc:set_timeout(5000)

        local url = "https://aiplatform.dev52.cbf.dev.paypalinc.com/bizlogging/insert?model_id=model_id"
        local body = '{"metadata_schema": ["request_body"],"variable_schema": ["response_body"]}'
        local headers = {
            ["Content-Type"] = "application/json",
            ["accept"] = "*/*",
        }

       local res, err = httpc:request_uri(url, {
           method = "POST",
           body = body,
           headers = headers,
           ssl_verify = false,
           timeout = 1000,
       })

       ngx_log(ngx_ERR, "success to request: ", res.status)

        local ok, err1 = httpc:set_keepalive(60000, 100)
        if not ok then
            ngx_log(ngx_ERR, "failed to set keepalive: ", err1)
        end
    }
}`
阅读 686
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏