how-to-configure-haproxy-statics

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

examples/haproxy/haproxy.cfg

  1. /etc/haproxy/haproxy.cfg
  2.  
  3. frontend home
  4. bind 127.0.0.1:3000
  5. use_backend flask
  6.  
  7. backend flask
  8. balance roundrobin
  9. server server1 127.0.0.1:5001
  10. server server1 127.0.0.1:5002
  11.  
  12. listen stats
  13. bind :9000
  14. stats enable
  15. stats hide-version
  16. stats refresh 30s
  17. stats show-node
  18. stats uri /stats
  19.  
  20.  

examples/haproxy/web.py

  1. from flask import Flask, request
  2. import sys
  3. from datetime import datetime
  4. app = Flask(__name__)
  5.  
  6. @app.route("/")
  7. def hello():
  8. return 'Hello <br>Running on port {}<br>Loaded at {}'.format(port, datetime.now())
  9.  
  10.  
  11. if __name__ == "__main__":
  12. if len(sys.argv) < 2:
  13. exit("Need port number")
  14. port = int(sys.argv[1])
  15. app.run(port = port)
  16.  

python web.py 5001