set $req_header "";
set $resp_header "";
header_filter_by_lua_block{
local h = ngx.req.get_headers();
for k, v in pairs(h) do
ngx.var.req_header = ngx.var.req_header .. k.."="..v.." ";
end
local rh = ngx.resp.get_headers();
for k, v in pairs(rh) do
ngx.var.resp_header = ngx.var.resp_header .. k.."="..v.." ";
end
}
lua_need_request_body on;
set $resp_body "";
body_filter_by_lua_block {
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
}
# access_log /dev/stdout log_req_resp;
access_log /var/log/nginx-access.log log_req_resp;
log_format log_req_resp '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" '
'$request_time req_header:"$req_header" resp_header:"$resp_header" '
'req_body:"$request_body" resp_body:"$resp_body"';
request headers:$http_<header>
sent headers: $sent_http_<header>
It works! 谢谢 / many thanks!