nginx+nodejs+socket.io ERR_CONNECTION_TIMED_OUT

nginx+nodejs+socket.io ERR_CONNECTION_TIMED_OUT

我几乎尝试了所有可以在论坛和博客中找到的解决方案,但我运气不好,这就是我现在寻求任何帮助的原因。

情况是这样的,我目前正在使用 Ubuntu 并且我有 运行 2 个插座,之前 运行 完美但是当我尝试再添加 1 个插座时问题出现了(ERR_CONNECTION_TIMED_OUT)。

这是我在 NGINX 上为我的第三个套接字所做的设置

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";
  }
}

这与我的第一个 2 个应用程序完全相同的 nginx 设置,这就是为什么我很难调试它,还有 nodejs 服务器。

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

在前端

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

这似乎不正确:

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

端口 3210 是 Express 正在侦听的端口,鉴于您正在使用 Nginx 进行代理,我希望客户端应该连接到 Nginx,而不是 Express:

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

(前提是Nginx是运行在80端口)