-
-
Save krast/14e3ea8060d212237fb3ac373c91f3f4 to your computer and use it in GitHub Desktop.
HAProxy: Route requests based on an environment variable
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
frontend http | |
bind 10.0.0.1:80 | |
mode http | |
# Add a new header with the environment variable and the path concatenated | |
http-request set-header X-ROUTING %[env(SERVER_AUTH)]::%[path] | |
# Then compare the value using a regular expression with back-references | |
# We need to use a named capture because of "reasons". Backreferences to normal captures seem to be rejected by HAProxy | |
use_backend app if { req.hdr(X-ROUTING) -m reg ^(?<auth>.+)==\1 } | |
# Cleanup in case we hadn't matched yet | |
http-request del-header X-ROUTING | |
default_backend default | |
backend app | |
# ... | |
backend default | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment