I would like to ask how HAProxy can help in routing requests depending on parts of the URL.
To give you an overview of my setup, I have the HAProxy machine and the two backends:
The use-case:
I'm expecting to route requests depending on the URL:
The blog access URL is "/server/blog/lang/articlexx" so I have to rewrite the original client request to that format--which is basically switching "blog" and "lang".
From how I understood the configuration documentation and some posts on the net, I could use reqrep/reqirep to change the request HTTP headers before it gets passed to a backend. And if that's right, then this configuration should work:
frontend vFrontLiner
bind x.x.x.x:x
mode http
option httpclose
default_backend iis_website
# the switch: x/lang/blog -? x/blog/lang
reqirep ^/(.*)/(blog)/(.*) /if\2/\1/\3
acl blog path_beg -i /lang/blog/
use_backend blog_website if blog
backend blog_website
mode http
option httpclose
cookie xxblogxx insert indirect nocache
server BLOG1 x.x.x.x:80 cookie s1 check inter 5s rise 2 fall 3
server BLOG2 x.x.x.x:80 cookie s2 check inter 5s rise 2 fall 3 backup
The problem: The requests being received by the blog_website backend is still the original URL "x/lang/blog".
I might have missed something on the regex part but my main concern is whether my understanding correct or not to use the reqirep in the first place. I would appreciate any help.
Thanks very much.
Access Control Lists, or ACLs, in HAProxy allow you to test various conditions and perform a given action based on those tests.
The frontend is the node by which HAProxy listens for connections. Backend nodes are those by which HAProxy can forward requests. A third node type, the stats node, can be used to monitor the load balancer and the other two nodes.
Your regex is wrong, you're assuming the server is in the request path. To match the request paths in the headers use a regex like this one:
reqrep ^([^\ ]*)\ /lang/blog/(.*) \1\ /blog/lang/\2
you can use reqirep as well but that is only useful if your servers actually serve /BLog/lAnG/
as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With