Hilo
Hilo

Reputation: 869

nginx as a proxy for NodeJS+socket.io: client not receiving notifications

I have nginx configured to proxy websockets like this:

location /socket.io {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

}

The clients connect fine but when the server emits a notification:

io.sockets.emit("update",data);

the client never receives it:

var socket = io.connect("http://" + hostip + "/socket.io");
socket.on("update",function(data)
{
  console.log("got update: " + data);
});

If I bypass nginx everything works as expected:

var socket = io.connect("http://" + hostip + ":8000");
socket.on("update",function(data)
{
  console.log("got update: " + data);
});

What am I missing? As an aside, why isn't the bypassing of nginx a single origin policy violation? Thanks.

Upvotes: 3

Views: 2505

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146124

Try just var socket = io.connect(location.host); in the browser. I don't think you want the /socket.io path.

Upvotes: 6

Related Questions