Gerald Gerald - 2 months ago 18
Node.js Question

nginx+nodejs+socket.io ERR_CONNECTION_TIMED_OUT

I almost tried any solution I can find in forums and blogs but I have no luck that's why I'm asking for any help right now.

Here's the situation, I am currently using Ubuntu and I'm running 2 sockets in it before which running perfectly but when I tried to add another 1 more socket the problem arise (The ERR_CONNECTION_TIMED_OUT).

Here is my set up on NGINX for my third socket

upstream stream {
server localhost:3210;
}

server {
location /socket.io {
proxy_pass http://stream;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}


This is the same exact nginx setup that I have had with my first 2 app, that's why I'm having a hard time to debug it, also with the nodejs server.

http.listen(3210, function(){
console.log('Listening on Port 3210');
});


and on front-end

var socket = io.connect('http://testapp.com:3210');

Answer

This seems incorrect:

var socket = io.connect('http://testapp.com:3210');

Port 3210 is what Express is listening on, and given that you're proxying using Nginx I'd expect that the client should connect to Nginx, not Express:

var socket = io.connect('http://testapp.com');

(provided that Nginx is running on port 80)