Websocket connection error with Apache 2.4 Proxy


#1

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.


#2

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]


#3

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/

</VirtualHost>