Repository navigation
WebSocket connection failed with Docker setup behind Apache reverse proxy #887
|
Hi everyone, I'm having trouble getting the WebSocket/NATS connection working in my Docker setup behind an Apache reverse proxy. Everything is running on the same server, with Apache handling SSL on port 443 for the main domain and plugnmeet running in a Docker container. The main web frontend loads correctly, but the WebSocket connection fails with a In the browser console, I get: I've already tried changing and remapping the ports (8222, 8223, 8224, 8226) in It seems like the frontend JS client keeps trying to open the WebSocket connection directly on the root domain (wss://meet.knnia.com:8226/) instead of connecting to NATS correctly. Has anyone encountered a similar issue with Docker + Apache, or does anyone know the correct way to configure Thanks! |
Replies: 1 comment 1 reply
|
The client isn't guessing that URL — it's reading it from your config. Since Apache already terminates TLS on 443, don't expose the NATS port at all. Point the client at a path on your normal domain and let Apache proxy it. config.yaml: nats_info:
nats_urls:
- "nats://host.docker.internal:4222"
nats_ws_urls:
- "wss://meet.knnia.com/nats"Keep NATS itself plain, since Apache is doing the TLS. In Then in your Apache vhost for port 443, before the main RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule ^/nats(.*) L]
ProxyPass /nats ws://12
ProxyPassReverse /nats ws://127.0.0.1:8222/You need a2enmod proxy proxy_http proxy_wstunnel rewrite && systemctl restart
apache2Make sure port 8222 from the container is published to 127.0.0.1 only in To check it before touc curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" \
-H "Sec-WebSocket-Vert-Key:dGhlIHNhbXBsZSBub25jZQ==" \
https://meet.knnia.coA |
The client isn't guessing that URL — it's reading it from your config.
nats_info.nats_ws_urlsinconfig.yamlis sent to the browser and used verbatim for the WebSocket connection. Sowss://meet.knnia.com:8226/means that's literally what's in your config right now. No amount of Apache tuning will change it.Since Apache already terminates TLS on 443, don't expose the NATS port at all. Point the client at a path on your normal domain and let Apache proxy it.
config.yaml:
Keep NATS itself plain, since Apache is doing the TLS. In
nats_server.conf: