Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox Keep-Alive, Upgrade ruining websocket through apache reverse proxy

I have the following apache2 configuration that is working for chrome and internet explorer:

Listen 80

IncludeOptional conf.d/*.conf
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so

<VirtualHost *:80>
        #ProxyRequests On
        ProxyPass / http://IP:8585/
        ProxyPassReverse / http://IP:8585/

        ProxyPass /call  ws://IP:8585/call
        ProxyPassReverse /call  ws://IP:8585/call

        ProxyPass /call/  ws://IP:8585/call/
        ProxyPassReverse /call/  ws://IP:8585/call/

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

</VirtualHost>

The problem is it does not work through firefox.

The only difference I have seen is that firefox sends Connection: keep-alive, Upgrade instead of simply Upgrade.

Do I need to change my Rewriterule ?

like image 545
Menelaos Avatar asked Apr 24 '26 17:04

Menelaos


1 Answers

Yes, you will need to add a condition to your rewrite rules. The below configuration will work as it checks for Connection values of Upgrade or keep-alive, Upgrade:

RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC,OR]
RewriteCond %{HTTP:CONNECTION} ^keep-alive,\ Upgrade$ [NC]
RewriteRule .* ws://localhost:8585%{REQUEST_URI} [P]
like image 182
Jon Ruddell Avatar answered Apr 26 '26 07:04

Jon Ruddell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!