Trevor Reimer
Trevor Reimer

Reputation: 304

Websocket is connecting on Chrome but not on Firefox

I am working on a apache proxy to WebSockets and the connection works great on Chrome and Safari Mobile but Firefox returns a 200 Ok Status and disconnects.

The server in question is a Centos 7 server running Apache and the websocket is provided by NodeJS.

<VirtualHost *:443>
    ServerAdmin [email protected]
    ServerName alpha.example.com
    ServerAlias www.alpha.example.com
    DocumentRoot public_html/
    ErrorLog logs/error.log

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    SSLProxyEngine On

    Include cert.pem
    SSLCertificateKeyFile privkey.pem
    SSLCertificateChainFile chain.pem

    ProxyRequests Off

    RewriteEngine On

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

    ProxyPass /ws http://127.0.0.1:8080
    ProxyPassReverse /ws http://127.0.0.1:8080

</VirtualHost>

Chrome connects to the server and I can send events both ways. Firefox attempts a connection but then closes immediately with a 200 Ok Status but logs Firefox can’t establish a connection to the server at wss://alpha.example.com/. Firefox however can load Proxy requests like https://alpha.example.com/ws

Upvotes: 4

Views: 822

Answers (1)

fl4l
fl4l

Reputation: 1640

The behaviour is due to the different Connection header in the GET call.

for Chrome is:

Connection: Upgrade

while for Firefox is

Connection: keep-alive, Upgrade

So, you need to change the RewriteCond for Connection to:

RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]

Also please see: https://stackoverflow.com/a/34371105/2186777

Upvotes: 1

Related Questions