gpt4 book ai didi

node.js - NodeJS 和 NginX 的 SocketIO 连接错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:07:38 25 4
gpt4 key购买 nike

当我尝试使用使用 nginx 的 nodejs 应用程序时,出现以下错误:

    2015/04/20 22:34:08 [error] 29607#0: *1 connect() failed (111: Connection 
refused) while connecting to upstream, client: myipaddress, server:
mydomain, request: "GET /socket.io/?EIO=3&transport=polling&
t=1429583647703-9 HTTP/1.1", upstream: "http://127.0.0.1:3000 /socket.io
/?EIO=3&transport=polling&t=1429583647703-9", host: "mydomain",
referrer: "http://mydomain"

我的nginx sites-available/default文件如下:

  server {
listen 80;
server_name mydomain;
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl;
server_name mydomain.com;
ssl on;
ssl_certificate /path/to/certificate;
ssl_certificate_key /path/to/certificate-key;

location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;

}
ssl_prefer_server_ciphers On;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3 DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5;

}

我正在使用 express,它有一个配置如下的 http 服务器:

app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});

var io = require("socket.io").listen(server);

如有任何帮助,我们将不胜感激。

最佳答案

原来我收到这个错误是因为我的 socket.io 代码没有被正确验证。可以在文档中看到正确的方法 here像这样:

io.use(function(socket, next) {
var handshakeData = socket.request;
// make sure the handshake data looks good as before
// if error do this:
// next(new Error('not authorized');
// else just call next
next();
});

关于node.js - NodeJS 和 NginX 的 SocketIO 连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29761997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com