需求,在nginx日志中打印出请求的response详细信息,
但是配置好了相关lua脚本之后resp_body为空;
nginx.conf 相关配置如下
由于有多个server,所以在很多server都加入了以下lua脚本
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
';