Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox can't establish a connection to WSS

I have a websocket server hostet with Spring Boot Websockets. Safari, Chrome and Edge can connect, but Firefox can't. Error:

Firefox kann keine Verbindung zu dem Server unter wss://MY_DOMAIN/growth-websocket/933/omw002tp/websocket aufbauen.

(= "Firefox can't establish a connection to the server at wss://...")

I am proxying the WebSockets with Apache:

RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* ws://localhost:4567%{REQUEST_URI} [P]

Thanks for your help!

like image 702
Timo Zikeli Avatar asked Aug 02 '17 19:08

Timo Zikeli


1 Answers

I got this working on my Docker OIDC proxy after a few tries. The tricky bit is to allow it to work when the proxied URI for websockets and normal HTTP is the same. If it were distinct we can simply have another ProxyPass/ProxyPassReverse combination before it.

To support this the Rewrite engine is used to detect whether the Upgrade and Conntextion headers are set and if so proxy accordingly. The second tricky bit [though I am not sure why] is to put it after the ProxyPass and ProxyPassReverse directives.

Here is the code from https://github.com/trajano/docker-oidc-proxy/blob/master/oidc-proxy.conf in context

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
LoadModule rewrite_module modules/mod_rewrite.so

...

ProxyPass "/" "http://${SERVICE_NAME}:${SERVICE_PORT}/"
ProxyPassReverse "/" "http://${SERVICE_NAME}:${SERVICE_PORT}/"

ProxyPreserveHost On
ProxyVia On

RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* ws://${SERVICE_NAME}:${SERVICE_PORT}%{REQUEST_URI} [P]

I was able to successfully verify this with a Jupyter notebook server which uses Web Sockets.

like image 65
Archimedes Trajano Avatar answered Oct 05 '22 18:10

Archimedes Trajano