HAProxy community

HAPROXY TCP Forward Based on Server or URL

I have a docker swarm with 3 manager nodes that I would like to load balance. I have 2 stacks running on the swarm right now. The stacks are using the following ports.
Stack1
3080 - Web
3443 - Secure Web
3022 - SSH
Stack2
4443 - Secure Web
4022 - SSH
4877 - Some TCP Non-Web Service

I would like to point DNS entries to a floating IP on my HAProxy servers, for example stack1.domain.com -> VRRP_IP, stack2.domain.com -> VRRP_IP.
Then I would like to have users access the stacks like this and have the traffic forwarded and load balanced to one of the master nodes.
Stack1
stack1.domain.com:80 -> masterX.domain.com:3080
stack1.domain.com:443 -> masterX.domain.com:3443
stack1.domain.com:22 -> masterX.domain.com:3022
Stack2
stack2.domain.com:443 -> masterX.domain.com:4443
stack2.domain.com:22 -> masterX.domain.com:4022
stack2.domain.com:877 -> masterX.domain.com:4877
OR this way if necessary, up unpreferred
Stack1
haproxy.domain.com/stack1:80 -> masterX.domain.com:3080
haproxy.domain.com/stack1:443 -> masterX.domain.com:3443
haproxy.domain.com/stack1:22 -> masterX.domain.com:3022
Stack2
haproxy.domain.com/stack2:443 -> masterX.domain.com:4443
haproxy.domain.com/stack2:22 -> masterX.domain.com:4022
haproxy.domain.com/stack2:877 -> masterX.domain.com:4877

My question is, can I redirect requests based on Server Name and/or URL in HAProxy for Non-Web traffic? I’m looking for some type of variable that will give me the destination server DNS address or URL. If I really have to, I can create separate floating IP’s for stack1.domain.com and stack2.domain.com.

Thanks

There are no hostname’s in the socket API and there is no URL in arbitrary TCP traffic.

With HTTPS we can use SNI, but that’s about the only protocol (other than HTTP of course) where we can extract the hostname out of it.

If SSH and other TCP services are required for this, than you need dedicated floating IP’s for the different stacks.