Hi folks, I’m trying to come up with a scheme by which the backend server port is selected based on some parameters of the request. For example, some requests might go to backend foo, server port M, while others might go to backend foo, server port N. Rather than have backends foo_M and foo_N, I’d like it to be dynamic.
The backend selection works fine, but when I try to define the server with the dynamic port, I get a syntax error. I’ve tried numerous ways of interpolating the string in the server line, most of which I’m embarrassed to even show because they are obviously not right. Here’s an example of what I’m trying to do (HAProxy 1.6+):
backend foo
server foo1 127.0.0.1:%[var(txn.service_port)]
Is there a proper way to accomplish this? Is it just not possible to have a dynamic port due to some internal operational characteristics of HAProxy?
Failing that, I’m aware that HAProxy will use the original dst_port as the server port if it is omitted. Is there some way to override the value of dst_port before calling use_backend
?
I have an idea on how to make this work using a dummy bind address and HTTP redirects, but that is undesirable for obvious reasons. Thank you in advance for any insight you can offer into better options.