Last active
July 13, 2021 21:30
-
-
Save haproxytechblog/7530f77fdca333d6a3e41912b40e525a to your computer and use it in GitHub Desktop.
HAProxy Configuration Basics: Load Balance Your Servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaults | |
mode http | |
timeout client 10s | |
timeout connect 5s | |
timeout server 10s | |
timeout http-request 10s | |
frontend myfrontend | |
bind 127.0.0.1:80 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo systemctl restart haproxy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl 127.0.0.1:80 | |
<html><body><h1>503 Service Unavailable</h1> | |
No server is available to handle this request. | |
</body></html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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/) ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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