2

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:

global
     log 127.0.0.1 local1 notice
     tune.ssl.default-dh-param 2048
defaults
     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 192.168.203.139:80

Any ideas on how to get each request logged?

Glorfindel
  • 1,213
  • 3
  • 15
  • 22
Josh Moore
  • 253
  • 3
  • 6
  • 14
  • 1
    Have you tried to add also in the frontend section "log 127.0.0.1 local1 notice" and the following parameters "option httplog" and "option dontlognull". Take a look also here http://serverfault.com/questions/647395/haproxy-not-logging-requests – DarkVex Mar 03 '17 at 21:41

2 Answers2

3

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
cerberus
  • 322
  • 3
  • 8
2

You have to put

mode http
option httplog 

in your frontend in order to log HTTP requests.

Mo3m3n
  • 414
  • 2
  • 6