Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@shoaibjdev

This comment has been minimized.

Copy link

@shoaibjdev shoaibjdev commented Jan 29, 2019

Hi,
Can you share log-format for capturing res.body?

@YuriyTigiev

This comment has been minimized.

Copy link

@YuriyTigiev YuriyTigiev commented Feb 19, 2020

How to capture the response body? Nginx support this - https://serverfault.com/questions/491560/logging-the-response-body-with-nginx-lua

@lazywithclass

This comment has been minimized.

Copy link
Owner Author

@lazywithclass lazywithclass commented Apr 5, 2020

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 ^^"

@pstjxp

This comment has been minimized.

Copy link

@pstjxp pstjxp commented Apr 28, 2020

        ## ------ 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!

@ValeryDubrava

This comment has been minimized.

Copy link

@ValeryDubrava ValeryDubrava commented Dec 25, 2020

Is it possible to capture all headers?

@deajan

This comment has been minimized.

Copy link

@deajan deajan commented Aug 6, 2021

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":"-"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment