-
-
Save lazywithclass/d255bb4d2086b07be178 to your computer and use it in GitHub Desktop.
global | |
log 127.0.0.1 local0 | |
user root | |
group root | |
daemon | |
defaults | |
log global | |
mode http | |
option httplog | |
option dontlognull | |
retries 3 | |
option redispatch | |
timeout connect 5000 | |
timeout client 120000 | |
timeout server 90000 | |
frontend www-http | |
bind 0.0.0.0:9000 | |
option http-buffer-request | |
declare capture request len 400000 | |
http-request capture req.body id 0 | |
log-format {"%[capture.req.hdr(0)]"} | |
default_backend node-servers | |
backend node-servers | |
server node google.com:80 maxconn 20 |
How to capture the response body? Nginx support this - https://serverfault.com/questions/491560/logging-the-response-body-with-nginx-lua
Hello both, sorry I did not see these notifications, it's ages since I used HAProxy, I'm afraid I do not remember and at this point I'd be too late anyway ^^"
## ------ LOG ----------
#no log ####this is real line USE THIS to disable log!!! when commented allows log
mode http
option http-buffer-request
declare capture request len 40000000
http-request capture req.body id 0
capture request header user-agent len 150
capture request header Host len 15
log-format '{"srcIP":"%[src]","backend":"%s","bIP":"%si","bPORT":"%sp","method":"%[capture.req.method]","user-agent":"%[capture.req.hdr(1),json(utf8s)]","uri":"%[capture.req.uri]","body":"%[capture.req.hdr(0)]"}'
## --------------------
DONT USE IT IN PRODUCTION! it will kill performance dependent on log method more or less :P Its also not safe and breaks bunch of laws. Remember!
Is it possible to capture all headers?
Anybody got the request body captured ?
I've tried with both haproxy 1.8 and 2.2, and all I get for the captured body is "-"
My frontend looks like
frontend frt_http
option httplog
option http-buffer-request
declare capture request len 400000
http-request capture req.body id 0
capture request header user-agent len 150
capture request header Host len 25
log-format '{"srcIP":"%[src]","backend":"%s","bIP":"%si","bPORT":"%sp","method":"%[capture.req.method]","user-agent":"%[capture.req.hdr(1),json(utf8s)]","uri":"%[capture.req.uri]","body":"%[capture.req.$
My log output looks like
{"srcIP":"XX.XX.XX.XX","backend":"<NOSRV>","bIP":"-","bPORT":"-","method":"POST","user-agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/92.0.4515.115 Safari\/537.36","uri":"/index.html","body":"-"}
anyone was able to log body? it return empty body "-"
@lynomet I've success with it, try this:
frontend localhost
...
http-request capture req.hdr_names len 50
http-request capture req.hdr len 100
http-request capture req.body len 8000
log-format "%r:\n%[capture.req.hdr(0)]\n%[capture.req.hdr(1)]\n%[capture.req.hdr(2)]"
log /debug-log.socket len 8192 local2 debug
If I understand correctly index of capture.req.hdr refers to each line http-request capture ...
@ValeryDubrava Thanks for the reply
i have tryied your config but i still get empty body "-"
i wounder what haproxy version are you using? i'm using v2.0.29
i think by now i have tried all combinations..nothing works
## ------ LOG ---------- #no log ####this is real line USE THIS to disable log!!! when commented allows log mode http option http-buffer-request declare capture request len 40000000 http-request capture req.body id 0 capture request header user-agent len 150 capture request header Host len 15 log-format '{"srcIP":"%[src]","backend":"%s","bIP":"%si","bPORT":"%sp","method":"%[capture.req.method]","user-agent":"%[capture.req.hdr(1),json(utf8s)]","uri":"%[capture.req.uri]","body":"%[capture.req.hdr(0)]"}' ## --------------------
DONT USE IT IN PRODUCTION! it will kill performance dependent on log method more or less :P Its also not safe and breaks bunch of laws. Remember!
this works for me on haproxy 2.4, thanks
Hi,
Can you share log-format for capturing res.body?