1
votes

I am running a little website using IIS 7.5 on Windows Server 2008 R2. I've got a node.js application too running on port 3000.

Http calls from the website (client browser) are reverse proxied from http://example.com/node/whatever to http://localhost:3000/whatever. Everything works fine so far.

The problem is when i try to use socket.io.

I am receiving:

    WebSocket connection to 'ws://example.com/socket.io/?EIO=3&transport=websocket&sid=adb9WRpoMFYRoS0vAAAB' 
failed: Error during WebSocket handshake: Unexpected response code: 502 

I am pretty sure, if i am not wrong, that:

It does forward the initial request to my server as the initial request to a websocket server is a standard HTTP request (with some additional headers). IIS does know about that and simply forwards the request. However, upon receiving the websocket request the websocket server sends a 101 response and switch into websocket mode. IIS does not understand the websocket traffic and it is not able to proxy that.

Is there a trick or solution to configure the reverse proxy for the ws:// adresses?

1
I've been told that maybe a COMET proxy could help, but i've not idea on how to do that.. - Egidi
Which version of socket.io are you using ? Post 1.0 uses comet techniques (long-polling). Also, looks like you need Windows Server 2012 ? See blogs.technet.com/b/erezs_iis_blog/archive/2013/09/16/… alternatively for you : guyellisrocks.com/2014/06/… - nha
Also see this related serverfault thread : serverfault.com/questions/645077/… - nha

1 Answers

0
votes

I'll expand a bit on my comments. As far as I understand, you have several options :

So, which version of socket.io are you using ? See the docs for allowed transports (extract below) :

io.enable('browser client minification');  // send minified client
io.enable('browser client etag');          // apply etag caching logic based on version number
io.enable('browser client gzip');          // gzip the file
io.set('log level', 1);                    // reduce logging

// enable all transports (optional if you want flashsocket support, please note that some hosting
// providers do not allow you to create servers that listen on a port different than 80 or their
// default port)
io.set('transports', [
    'websocket'
  , 'flashsocket'
  , 'htmlfile'
  , 'xhr-polling'
  , 'jsonp-polling'
]);