Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Last active July 13, 2021 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haproxytechblog/7530f77fdca333d6a3e41912b40e525a to your computer and use it in GitHub Desktop.
Save haproxytechblog/7530f77fdca333d6a3e41912b40e525a to your computer and use it in GitHub Desktop.
HAProxy Configuration Basics: Load Balance Your Servers
defaults
mode http
timeout client 10s
timeout connect 5s
timeout server 10s
timeout http-request 10s
frontend myfrontend
bind 127.0.0.1:80
$ sudo systemctl restart haproxy
$ curl 127.0.0.1:80
<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>
$ python3 -m http.server 8000 --bind 127.0.0.1
Serving HTTP on 0.0.0.0 port 8000 (http://127.0.0.1:8000/) ...
defaults
mode http
timeout client 10s
timeout connect 5s
timeout server 10s
timeout http-request 10s
frontend myfrontend
bind 127.0.0.1:80
default_backend myservers
backend myservers
server server1 127.0.0.1:8000
$ curl 127.0.0.1:80
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
...
</html>
frontend myfrontend
bind 127.0.0.1:80
default_backend myservers
backend myservers
server server1 127.0.0.1:8000
server server2 127.0.0.1:8001
server server3 127.0.0.1:8002
frontend myfrontend
bind 127.0.0.1:80,127.0.0.1:81
use_backend special if { dst_port 81 }
default_backend myservers
backend myservers
server server1 127.0.0.1:8000
server server2 127.0.0.1:8001
backend special
server server3 127.0.0.1:8002
frontend myfrontend
bind 127.0.0.1:80
bind 127.0.0.1:81
use_backend special if { dst_port 81 }
default_backend myservers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment