首页 > 解决方案 > NodeJs Socket 部署在 AWS LoadBalancer 上不起作用

问题描述

我的 NodeJs Socket.io 在 HTTP 上运行良好,但是一旦我将实例添加到 AWS 负载均衡器并通过 HTTPS 访问它,它确实会连接一次,但之后它会一直断开连接。通过 Socket,我实现了聊天 - 所以只有一次双向通信发生,然后我得到错误记录“一个套接字与服务器断开连接”。以下是我的 AWS 配置 在此处输入图像描述

从客户端(Android),我正在使用 https://example.com

和来自 NodeJs NGINX 的日志

2021/11/13 16:58:58 [error] 21285#21285: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.27.33, server: , request: "GET /socket.io/?EIO=4&transport=polling HTTP/1.1", upstream: "http://127.0.0.1:8080/socket.io/?EIO=4&transport=polling", host: "domain.com"
2021/11/13 17:24:49 [error] 22100#22100: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.27.33, server: , request: "POST /socket.io/?EIO=4&transport=polling&sid=xLc-Bz_iYKAXXXXXX- HTTP/1.1", upstream: "http://127.0.0.1:8080/socket.io/?EIO=4&transport=polling&sid=xLc-Bz_iYKXXXXXX-", host: "doman.com"

标签: node.jsamazon-web-servicessocketsnginx

解决方案


推荐阅读