how-to-configure-haproxy-statics

the-four-essential-sections-of-an-haproxy-configuration

examples/haproxy/haproxy.cfg

/etc/haproxy/haproxy.cfg

frontend home
   bind 127.0.0.1:3000
   use_backend flask

backend flask
   balance roundrobin
   server server1 127.0.0.1:5001
   server server1 127.0.0.1:5002

listen stats
   bind :9000
   stats enable
   stats hide-version
   stats refresh 30s
   stats show-node
   stats uri /stats


examples/haproxy/web.py

from flask import Flask, request
import sys
from datetime import datetime
app = Flask(__name__)

@app.route("/")
def hello():
   return 'Hello <br>Running on port {}<br>Loaded at {}'.format(port, datetime.now())


if __name__ == "__main__":
   if len(sys.argv) < 2:
       exit("Need port number")
   port = int(sys.argv[1])
   app.run(port = port)

python web.py 5001