Skip to content
This repository

Sample HAProxy config

A simple, sample HAProxy config file for routing incoming requests to multiple goliath app servers: several app servers per API, and multiple API’s on the same, or multiple machines. For more details on the Haproxy syntax, please read the configuration documentation. Otherwise, the config file should be self-explanatory:

global
    pidfile /var/run/haproxy.pid
    log 127.0.0.1 local0 info

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:8000 weight 1 maxconn 50 check inter 4000
Something went wrong with that request. Please try again.