2
votes

I'm trying to use HAProxy as a dynamic proxy for backend hosts based on partial /path regex match. The use case is routing from an HTTPS frontend to a large number of nodes that come and go frequently, without maintaining an explicit mapping of /path to server hostnames.

Specifically in this case the nodes are members of an Amazon EMR cluster, and I'd like to reverse-proxy/rewrite HTTP requests like:

<haproxy>/emr/ip-99-88-77-66:4040               -> 99.88.77.66:4040
<haproxy>/emr/ip-55-44-33-22/ganglia            -> 55.44.33.22/ganglia
<haproxy>/emr/ip-11-11-11-11:8088/cluster/nodes -> 11.11.11.11:8088/cluster/nodes
...etc

dynamically.

As-in, parse the path beginning at /emr and proxy requests to an IP captured by the regex:

emr\/ip-(\d{1,3}-\d{1,3}-\d{1,3}-\d{1,3})(.*)

Is this possible with HAProxy? I know it's probably not the right tool for the job, but if possible (even non-performant) I'd like to use the tooling we already have in place.

tl;dr basically nginx proxy_pass, but with HAProxy and plucking a backend IP from the url.

Thanks!

3

3 Answers

0
votes

Yes its possible by using url filters in haproxy, see below link for more details. https://fossies.org/linux/haproxy/doc/internals/filters.txt

0
votes

Yes this can be done. I would recommend you use ACLs, as well as Roundrobin & checks, which will allow you to check to see if that instance is up before routing to it with a check. That way, the system will only route to service instances that are up and running, and will only have them preloaded for use if they are up.

In addition, this will also allow you to constantly cycle in and out instances, such as if your AWS instance costs change with any other providers you may have, and allows you to load balance with maximum cost savings in mind.

0
votes

yes, this is possible.. check the official manual:

Using ACLs and fetching samples