Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


igrigorik edited this page · 2 revisions

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:

    pidfile /var/run/
    log local0 info

    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
Something went wrong with that request. Please try again.