@yuriy.tigiev wrote:
Hello,
How to logging requests and responses body using Lua by haproxy?
I have made a configuration for nginx and would like to make a similar configuration for HAProxy. Can someone help me to adapt it?
worker_processes 1;
error_log logs/error.log;events {
worker_connections 1024;
}
http {
log_format log_req_resp '$remote_addr - $remote_user [$time_local] ’
'"$request" $status $body_bytes_sent ’
‘"$http_referer" “$http_user_agent” “$proxy_add_x_forwarded_for” “$http_x_real_ip” “$http_host” $request_time req_body:"$request_body" resp_body:"$resp_body"’;server { listen 8899; proxy_set_header X-Real-IP $http_x_real_ip; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-Host $http_host; access_log logs/access.log log_req_resp; 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 '; location / { proxy_pass http://172.30.128.11:3000; } }
}
Posts: 1
Participants: 1