Websocket connection error with Apache 2.4 Proxy

I have Meteor behind an Apache 2.4 server configured to proxy everything from 80 to 3000. Every page request works but I get the following error in the Chrome console:

I’ve read a fair bit about this and gather that there is a fallback that makes my pages work but this is not ideal and to fix it requires proxying websockets. The only instructions I’ve seen are for Nginx. Does anyone know how to do this for Apache 2.4? I have a very simple site and only proxy / currently.

Take a look at http://stackoverflow.com/a/25404972:

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

That answer is incomplete, or at least didn’t work for me.

I had to do:

sudo a2enmod proxy_wstunnel 

then restart Apache.

Also had to add a ProxyPass and ProxyPassReverse and changed ^Upgrade$ to Upgrade$ from another SO answer.

I checked on the console and there is no error now and no xhr requests. So I assume it’s working correctly

<VirtualHost *:80>
    ServerName  some-domain.com

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

    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/

1 Like

Confirmed that this setup is the absolute best Apache setup.