Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sample HAProxy config with logging.
pidfile /var/run/
log local0 info
ulimit-n 65536
mode http
clitimeout 600000 # maximum inactivity time on the client side
srvtimeout 600000 # maximum inactivity time on the server side
timeout connect 8000 # maximum time to wait for a connection attempt to a server to succeed
stats enable
stats auth admin:password
stats uri /monitor
stats refresh 5s
option httpchk GET /status
retries 5
option redispatch
errorfile 503 /path/to/503.text.file
balance roundrobin # each server is used in turns, according to assigned weight
frontend http
bind :80
monitor-uri /haproxy # end point to monitor HAProxy status (returns 200)
acl api1 path_reg ^/api1/?
acl api2 path_reg ^/api2/?
use_backend api1 if api1
use_backend api2 if api2
backend api1
# option httpclose
server srv0 weight 1 maxconn 100 check inter 4000
server srv1 weight 1 maxconn 100 check inter 4000
server srv2 weight 1 maxconn 100 check inter 4000
backend api2
option httpclose
server srv01 weight 1 maxconn 50 check inter 4000
# .. otherwise consider putting these two in /etc/rsyslog.conf instead:
$ModLoad imudp
$UDPServerRun 514
# ..and in any case, put these two in /etc/rsyslog.d/49-haproxy.conf:
local1.* -/var/log/haproxy_1.log
& ~
# & ~ means not to put what matched in the above line anywhere else for the rest of the rules
# Don’t forget to tweak the debug level in /etc/haproxy/haproxy.conf.
# Now do a quick:
>>> restart rsyslog
# And you’re done. Check for HAProxy logs in:
>>> tail -f /var/log/haproxy*.log
# Maybe set up a logrotate right away in "/etc/logrotate.d/haproxy":
rotate 4
reload rsyslog >/dev/null 2>&1 || true
Copy link

sbuzonas commented Sep 27, 2017

Why are you logging to local0 but capturing local1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment