I would like to configure HAProxy to handle multiple domains on a single listening port and route traffic to different backend services based on the requested domain name.
Is one of the backends needing to be a TCP a requirement? I’m not sure I understand that well.
I can already tell you it’s possible, but we might need more info. It would also be nice to know what you’ve tried so far.
yes
Depends
I’m not sure but I’d use SNI.
if you need to handle both tcp and http (l4/l7) traffic. You’d route it through TCP first. Anything that listens directly for TCP can be done like this
acl direct_tcp req.ssl_sni -i yoururl.com
and to select the backend based on the acl use_backend be_somebackend if direct_tcp
if you only have 2 backends, you can then use a default backend for all other traffic.
(I’m no expert btw, but I can share my experience).
Yes, having one backend use raw TCP is actually a requirement in my case. The backend service listens on both a TCP port and a WebSocket (HTTP/HTTPS) port at the same time.
What I’m trying to achieve is:
HAProxy listens on a single port (e.g. 443)
Based on the requested domain name:
domain1.com → forward to the TCP backend
domain2.com → forward to the WebSocket (HTTP) backend
From what I understand so far, a possible approach is to use TCP mode on the frontend and route based on SNI, something like:
Thank you for your reply. One of my services listens on a TCP port and a WebSocket port. HAProxy exposes only the listening port and uses multiple domains to distinguish between forwarding to the TCP or WebSocket service ports. I want to use this port for multiplexing and avoid maintaining multiple ports. It would be great if this could be achieved.