0

I have a webapp running on http://example.com:5000/

The website tries to establish a socket.io connection to that server to exchange some time critical data (multi player game).

Everything works fine that far...

Now I'm trying to get that whole thing production ready, so I want to make it available on a nicer URL: https://myapp.example.com/

To do so I configure my Apache server as follows:

ProxyPass / http://0.0.0.0:5000/
ProxyPassReverse / http://0.0.0.0:5000/

On the first glance everything seems to work - but socket.io can't switch from polling to websocket any more.

Javascript console shows this error:

socket.io.js:8 WebSocket connection to 'wss://myadpp.example.com/socket.io/?EIO=3&transport=websocket&sid=0bef58d5622f4d20b4c1d7f29c97a21d' failed: Error during WebSocket handshake: Unexpected response code: 200

It seems to be a very common setup - hiding a socket.io based webapp behind an apache proxy - but I can't find any working solutions online.

It seems that apache can't proxy ws:// connections, but I don't know what to do instead..

Found the solution here: WebSockets and Apache proxy : how to configure mod_proxy_wstunnel?

1 Answers1

1

Try loading the mod_proxy_wstunnel module: https://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html

Edit:

For you second question try this:

RewriteCond %{REQUEST_URI}  ^/socket.io            [NC]
RewriteCond %{QUERY_STRING} transport=websocket    [NC]
RewriteRule /(.*)           ws://0.0.0.0:5000/$1 [P,L]

RewriteCond %{QUERY_STRING} transport=polling    [NC]
RewriteRule /(.*)           http://0.0.0.0:5000/$1 [P,L]

ProxyPass / http://0.0.0.0:5000/
ProxyPassReverse / http://0.0.0.0:5000/
JollyGood
  • 45
  • 7
  • Thanks, I activated that one. Second half of the problem: socket.io sends HTTP and WS requests to same path "/socket.io/" - the only differ in parameter "transport"... put I don't know how to make that parameter part of the ProxyPass condition. http:// myapp.example.com/socket.io/?EIO=3&transport=polling&t=MdIyL-W&sid=... should be forwarded to http:// 0.0.0.0:5000 while ws://bam4.omnitopos.net/socket.io/?EIO=3&transport=websocket&sid=4912cea3deca44c6b3af3a205c61a048 should be forwarded to ws://0.0.0.0:5000 – Florian Metzger-Noel Mar 31 '19 at 08:56
  • Make a RewriteRule with a [P] parameter. You can see examples in that link you put yourself. – JollyGood Apr 01 '19 at 00:21