Last active
March 4, 2016 22:58
-
-
Save khoubyari/ed4c7e6935e469c6bc6b to your computer and use it in GitHub Desktop.
Configuring HAProxy 1.5.x to add Basic Auth and Health Check
This file contains 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
# | |
#1. Add an ACL for the top level routes you need to proxy | |
# | |
acl routes_to_proxy path_beg -i /my/path /other-path | |
# | |
#2. Associate the routes with a backend | |
# | |
use_backend my_backend if routes_to_proxy | |
# | |
#3. Create a list of credentials (note: passwords are in clear text. this is bad security practice.) | |
# | |
userlist UsersFor_MyApp | |
user myuser insecure-password mypassword | |
# | |
#4. Set up the backend as usual... this one has an optional health check defined (e.g. for a Spring Boot App https://goo.gl/u5KtaO) | |
# | |
backend my_backend | |
balance roundrobin | |
option httpchk GET /health | |
http-check expect status 200 | |
server myhost01 myhost01:8080 check port 8081 inter 60000 rise 3 fall 3 | |
server myhost02 myhost01:8080 check port 8081 inter 60000 rise 3 fall 3 | |
acl AuthOkay_MyApp http_auth(UsersFor_MyApp) | |
http-request auth realm MyAppRealm if !AuthOkay_MyApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment