# Help needed NGINX reverse proxy to NODE.JS

**URL:** <https://www.ruby-forum.com/t/help-needed-nginx-reverse-proxy-to-node-js/246102>\
**Category:** NGINX\
**Created:** [August 27, 2013, 4:57pm UTC](https://www.ruby-forum.com/t/help-needed-nginx-reverse-proxy-to-node-js/246102 "2013-08-27T16:57:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [August 27, 2013, 4:57pm UTC](https://www.ruby-forum.com/t/help-needed-nginx-reverse-proxy-to-node-js/246102/1 "2013-08-27T16:57:48Z")

</div>

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 ! 😉

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

---

<div class="post-metadata">

**Author:** ![ben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://www.ruby-forum.com/u/ben)\
**Post date:** [August 27, 2013, 6:02pm UTC](https://www.ruby-forum.com/t/help-needed-nginx-reverse-proxy-to-node-js/246102/2 "2013-08-27T18:02:43Z")

</div>

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 ! 😉

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

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![ben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://www.ruby-forum.com/u/ben)\
**Post date:** [August 27, 2013, 6:50pm UTC](https://www.ruby-forum.com/t/help-needed-nginx-reverse-proxy-to-node-js/246102/3 "2013-08-27T18:50:06Z")

</div>

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 😉

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 ??

---

<div class="post-metadata">

**Author:** ![ben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://www.ruby-forum.com/u/ben)\
**Post date:** [August 27, 2013, 7:15pm UTC](https://www.ruby-forum.com/t/help-needed-nginx-reverse-proxy-to-node-js/246102/4 "2013-08-27T19:15:15Z")

</div>

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 😉

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](http://nginx.org/en/docs/debugging_log.html) for details.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**
