nginx配置打印請求響應內容


#放在http{}里面
    log_format  kyh  ' [$time_local] "$request" $status \n'
        'req_header:"$req_header" \n req_body:"$request_body" \n'
        'resp_header:"$resp_header" \n  resp_body:"$resp_body"\n\n';


#以下loaction{}里的proxy_pass 語句下面
    #請求響應頭部    
        set $req_header "";
        set $resp_header "";
        header_filter_by_lua '
            local h1 = ngx.req.get_headers()
            for k1, v1 in pairs(h1) do
            ngx.var.req_header=ngx.var.req_header..k1..": "..v1
            end
        
            local h = ngx.resp.get_headers()
            for k, v in pairs(h) do
            ngx.var.resp_header=ngx.var.resp_header..k..": "..v
            end
        ';
        
        
         lua_need_request_body on;
    #響應頭部
        set $resp_body "";
        body_filter_by_lua '
            local resp_body = string.sub(ngx.arg[1], 1, 1000)
            ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_body
            if ngx.arg[2] then
                ngx.var.resp_body = ngx.ctx.buffered
            end
        ';

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM