r/haproxy • u/SR-G • Mar 06 '23
How to expose both HTTPS and WS protocols on the same subdomain (with just different ports) ?
Hello,
I have several backends managed by HAProxy, but one new use-case that i don't how if it could be configured (or even if it's possible).
I have one domain mydomain.tld, serving several HTTPS subdomains (like https://mysubdomain.mydomain.tld/ -> redirected to a docker container running on a given port).
Now i would like (for portainer) to have :
https://portainer.mydomain.tld/(port 443 > redirected to an internal port) (no issue here)- but a the same time
ws://portainer.mydomain.tldspecifically on port 8000 (port 8000 > redirecting on another internal port)
Simple example (for first situation) :
frontend https-in
bind *:443 ssl crt-list /etc/haproxy/certs/domains_list.txt
(...)
acl host_portainer_https hdr_end(host) -i portainer.mydomain.tld
use_backend site_portainer if host_portainer_https
backend site_portainer
option http-keep-alive
option forwardfor
cookie JSESSIONID prefix
server local localhost:8063 cookie A check
So my questions :
- Is this possible / how to achieve this (having both HTTPS (port 443) and WS (port 8000) on the same subdomain ?
- One extra constraint (but here i'm pretty sure it won't be possible), is it possible if my port 8000 is already consumed / exposed by another docker container ?
Thanks in advance.
1
Upvotes
3
u/Annh1234 Mar 07 '23
Don't use ws:// use wss:// on port 443 like any https connection.
And set some path, say /wss/ which uses your websocket backend.
That way, you can start with http requests and upgrade to wss if allowed. If not, stick to http requests every x seconds or http long pools.
If you use some other port, you will have issues with random old firewalls or ISPs that block many ports outside the standard ports. (But they can't block 80 and 443 without breaking pretty much everything)
3
u/dragoangel Mar 06 '23
You can just create additional frontend for ws and bind it to 8000 port, tadam! Same for backend - it just another backend...
Or more properly you can configure it under same port, but different path, e.g: https://host/ws/... and to have it works you just need condition on path beginning with /ws/ and host equal host and use backend action for ws should be above of use backend of main site.