Created
August 22, 2022 13:41
-
-
Save haproxytechblog/9338713adb7340e2201256adbb4a2dc4 to your computer and use it in GitHub Desktop.
Path-based Routing with HAProxy
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 mysite | |
bind :80 | |
# route to a backend based on path's prefix | |
use_backend app-a if { path /a } || { path_beg /a/ } | |
use_backend app-b if { path /b } || { path_beg /b/ } | |
backend app-a | |
# strip the prefix '/a' off of the path | |
http-request replace-path /a(/)?(.*) /\2 | |
server server1 127.0.0.1:8080 check maxconn 30 | |
backend app-b | |
# strip the prefix '/b' off of the path | |
http-request replace-path /b(/)?(.*) /\2 | |
server server1 127.0.0.1:8081 check maxconn 30 |
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
use_backend app-a if { path /a } || { path_beg /a/ } | |
use_backend app-b if { path /b } || { path_beg /b/ } |
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
use_backend app-a if { path /a /c /d } || { path_beg /a/ /c/ /d/ } |
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
acl app-a-path path /a /c /d | |
acl app-a-path path_beg /a/ /c/ /d/ | |
use_backend app-a if app-a-path |
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
backend app-a | |
http-request replace-path /a(/)?(.*) /\2 | |
server server1 127.0.0.1:8080 check maxconn 30 | |
backend app-b | |
http-request replace-path /b(/)?(.*) /\2 | |
server server1 127.0.0.1:8081 check maxconn 30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment