Help needed NGINX reverse proxy to NODE.JS

Hi,

I’ve tried this with NGINX 1.4.1-1ppa1~precise and node v0.10.17 and
just can’t get it to work.

What I’ve tried / what happens :
(a) Yes, I have tested this direct between client code and node
listening on 0.0.0.0 and it works as expected
(b) I have tried a multitude of alternative configs… adding a path
addribute to my node server config and tweaking proxy_pass
http://node_admin accordingly. That doesn’t work either.
© When running via NGINX, I only ever get two alerts, the “WebSocket
is supported by your Browser!” string and the “Connection is closed…”
string. Nothing happens in between, and nothing on the node console
either.
(d) Nothing in the NGINX logs either.

Help ! :wink:

Thanks !

Simple “hello world” style node script :

var WebSocketServer = require(‘ws’).Server
, wss = new WebSocketServer({host:‘localhost’,port: 8080});
wss.on(‘connection’, function(ws) {
ws.on(‘message’, function(message) {
console.log(‘received: %s’, message);
});
ws.send(‘something’);
});

Simple NGINX conf :

     upstream node_admin {
             server 127.0.0.1:8080;
             keepalive 64;
     }
     location /api {
             proxy_redirect off;
             proxy_http_version 1.1;
             proxy_pass http://node_admin;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection "upgrade";
             proxy_set_header Host $host;
     }

Simple client :

Run WebSocket

Hello!

On Tue, Aug 27, 2013 at 03:57:03PM +0100, Ben wrote:

http://node_admin accordingly. That doesn’t work either.
(c) When running via NGINX, I only ever get two alerts, the
“WebSocket is supported by your Browser!” string and the “Connection
is closed…” string. Nothing happens in between, and nothing on
the node console either.
(d) Nothing in the NGINX logs either.

Help ! :wink:

Nothing in nginx logs at all, even in access log? Sounds like a
DNS problem…


Maxim D.
http://nginx.org/en/donation.html

Nothing at all … I promise you ! (I’ve been tail -f’ing the logs) ,
and I can promise you its not a DNS problem because I can see the NGINX
default website on port 80 :wink:

I found a workaround setting “proxy_buffering off;” in nginx makes it
work again. Don’t know if this is the way it’s supposed to be and/or a
recommended way to do things ??

Hello!

On Tue, Aug 27, 2013 at 05:49:19PM +0100, Ben wrote:

Nothing at all … I promise you ! (I’ve been tail -f’ing the logs)
, and I can promise you its not a DNS problem because I can see the
NGINX default website on port 80 :wink:

The location with websocket proxy you are testing is on port 80
too. Do you see other requests to the host in access log?

I found a workaround setting “proxy_buffering off;” in nginx makes
it work again. Don’t know if this is the way it’s supposed to be
and/or a recommended way to do things ??

The fact that it helps indicate that connection is ok (that is,
you should see it in access log once it completes - unless you
disabled access logging or looking into wrong logs), but isn’t
considered to be upgraded to a websocket protocol for some reason.

Most obvious reason I can think of is an old version of nginx
actually running, the one without websocket proxy support
(something before 1.3.13 instead of 1.4.1 you claim in your
initial message). It’s trivial to check by looking into Server
header line returned.

If still no lock, try configuring a debug log and obtaining one
while trying a websocket request, see
A debugging log for details.


Maxim D.
http://nginx.org/en/donation.html