Configure HAProxy to Log Request BODY

hack_on picture hack_on · Nov 26, 2015 · Viewed 9.3k times · Source

I understand that it is possible to log the BODY of a POST request with HAProxy since version 1.6.0. The following mail archive indicates that we need to use req.body somehow and log the capture.req.hdr in the log-format.

The person asking in the above link had the following front-end in their config:

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)]"}

But presumably this is wrong, hence their question.

What is the exact syntax to do this?

Answer

hack_on picture hack_on · Nov 26, 2015

This worked for me with a custom log format:

global
        log     127.0.0.1 local0
        debug
        maxconn 2048
        ulimit-n 8012
#        ...

defaults
    mode http
    option httplog
    log-format frontend:%f/%H/%fi:%fp\ client:%ci:%cp\ GMT:%T\ body:%[capture.req.hdr(0)]\ request:%r
    option dontlognull
#   ...

frontend www-http
   log global
   option http-buffer-request
# id=0 to store body for logging
   declare capture request len 40000
   bind 7.7.7.7:8007 
   http-request capture req.body id 0

   default_backend www-backend

backend www-backend
    mode http
    option forwardfor
#   ...