I am setting up HAProxy as a load balancer and I can get it working (it is forwarding requests to backends). However, I cannot get it to log each request to a file. I can see system type messages like this:

Mar  3 19:36:33 rg-staging-balancer haproxy-systemd-wrapper[29244]: haproxy-systemd-wrapper: SIGTERM -> 8750.
Mar  3 19:36:33 rg-staging-balancer haproxy-systemd-wrapper[29244]: haproxy-systemd-wrapper: exit, haproxy RC=0
Mar  3 19:36:33 rg-staging-balancer haproxy-systemd-wrapper[18109]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

but not individual requests. I am running Ubuntu 16.04, HAProxy 1.7.2-1ppa1~xenial with this configuration:

     log local1 notice
     tune.ssl.default-dh-param 2048
     timeout client 10s
     timeout server 10s
     timeout connect 10s

frontend http
     reqadd X-Forwarded-Proto:\ https
     maxconn 2000
     bind :443 ssl crt /etc/ssl/haproxy.pem
     default_backend rails_servers
backend rails_servers
     mode http
     option httpchk
     option forwardfor
     server rg_staging

Any ideas on how to get each request logged?


Have you tried enabling UDP logging on rsyslog (disabled by default) and adding a facility for LOCAL1 (which is the facility you're using)?

Ensure that these lines are not commented out in /etc/rsyslog.conf

$ModLoad imudp

$UDPServerRun 514

Add this line to log HAProxy to the above configuration file:

local1.*    /var/log/haproxy.log

You have to put

mode http
option httplog 

in your frontend in order to log HTTP requests.

  • This will not help if you are using haproxy to terminate TLS and thus have mode tcp set.
    – Andrew
    Jul 3 '19 at 1:10
  • 1
    No you can still use "mode http" if you are terminating TLS (decrypting traffic)
    – Mo3m3n
    Jul 4 '19 at 22:04
  • Yep no need for "mode tcp" when terminating TLS, this was a misconfiguration I had!
    – Andrew
    Jul 11 '19 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.