How to connect socket.io through a reverse proxy server

I am trying to connect to socket.io server due to reverse apache proxy. I have apache running on port 8888. The nodejs server runs on the same computer on port 9096. For testing, the proxy server is configured on my local computer as follows:

ProxyPass /some/path http://localhost:9096 ProxyPassReverse /some/path http://localhost:9096 

In the client code, I am doing something like this:

 var socketUrl = 'http://localhost:8888/some/path/namespace'; var socket = io.connect(socketUrl); 

This leads to the following behavior.

First, my client requests a socket.io.js script at:

 http://localhost:8888/some/path/socket.io/socket.io.js -> 200 ok 

Then the socket tries to connect at:

 localhost:8888/socket.io/1?123983759 -> 404 not found 

I found the "resource" configuration for socket.io, but it just looks like where the socket.io.js script is coming from, but not the URL to which it is trying to connect. It seems to connect with the root of origin of the client.

How can I connect it to local: 8888 / some / path / socket.io / 1 123983759

?

+6
source share
1 answer

In the client code, you must set the base path with the resource parameter, for example:

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

All Articles