Basj Basj - 6 months ago 111
Node.js Question

WebSockets and Apache proxy : how to configure mod_proxy_wstunnel?

I have :

  1. Apache
    (v2.4) on port 80 of my server for
    , with mod_proxy and mod_proxy_wstunnel enabled

  2. node.js +
    on port 3001 of the same server.

(with port 80) redirects to 2. thanks to the method described here. I have set this in the Apache configuration:

<VirtualHost *:80>
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
ProxyPass / ws://localhost:3001/
ProxyPassReverse / ws://localhost:3001/

It works for everything, except the websocket part :
are not transmitted like it should by the proxy.

When I access the page on
, I have:

Impossible to connect ws://

Question: How to make Apache proxy the WebSockets as well?


I finally managed to do it, thanks to this topic.


1) Have Apache 2.4 installed (doesn't work with 2.2), a2enmod proxy and a2enmod proxy_wstunnel

2) Have nodejs running on port 3001

3) Do this in the Apache config

<VirtualHost *:80>

  RewriteEngine On
  RewriteCond %{REQUEST_URI}  ^/            [NC]
  RewriteCond %{QUERY_STRING} transport=websocket    [NC]
  RewriteRule /(.*)           ws://localhost:3001/$1 [P,L]

  ProxyPass / http://localhost:3001/
  ProxyPassReverse / http://localhost:3001/