Skip to content

Instantly share code, notes, and snippets.

@icespider
Forked from hzbd/haproxy.config
Created September 19, 2018 02:25
Show Gist options
  • Save icespider/70157424fb5797881081812add114bd1 to your computer and use it in GitHub Desktop.
Save icespider/70157424fb5797881081812add114bd1 to your computer and use it in GitHub Desktop.
Sample HAProxy config with logging.
global
pidfile /var/run/haproxy.pid
log 127.0.0.1 local0 info
ulimit-n 65536
defaults
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 127.0.0.1:9000 weight 1 maxconn 100 check inter 4000
server srv1 127.0.0.1:9001 weight 1 maxconn 100 check inter 4000
server srv2 127.0.0.1:9002 weight 1 maxconn 100 check inter 4000
backend api2
option httpclose
server srv01 127.0.0.1:9003 weight 1 maxconn 50 check inter 4000
# .. otherwise consider putting these two in /etc/rsyslog.conf instead:
$ModLoad imudp
$UDPServerAddress 127.0.0.1
$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
# http://serverfault.com/questions/214312/how-to-keep-haproxy-log-messages-out-of-var-log-syslog
# 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":
/var/log/haproxy*.log
{
rotate 4
weekly
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
reload rsyslog >/dev/null 2>&1 || true
endscript
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment