How to connect socket.io through a reverse proxy How to connect socket.io through a reverse proxy apache apache

How to connect socket.io through a reverse proxy


In your client code you have to set the base path with the resource option, like so:

var socket = io.connect('http://localhost:8888', {resource: '/some/path/socket.io'});


Had this issue myself, The example by YED is still pointing out to a solution which connects to the nodeJs directly and not via the Reverse Proxy.

Normally you want index.html to connect over the Apache Reverse Proxy and not directly. An example is provided at Socket.io via Apache Reverse Proxy

basically, you have to enable proxy_wstunnel as well and add the following to the your virtual host configuration

RewriteCond %{REQUEST_URI}  ^/socket.io            [NC]RewriteCond %{QUERY_STRING} transport=websocket    [NC]RewriteRule /(.*)           ws://dev-ip-machine:8001/$1 [P,L]ProxyPass /chat http://dev-ip-machine:8001ProxyPassReverse /chat http://dev-ip-machine:8001ProxyPass        /socket.io  http://dev-ip-machine:8001/socket.ioProxyPassReverse /socket.io  http://dev-ip-machine:8001/socket.io