简体   繁体   English

套接字 io 在我的 nodejs express web 应用程序中使用 nginx 进行负载平衡后工作了一段时间

[英]socket io working some times after doing load balancing using nginx in my nodejs express web app

I am working with a node js express app.我正在使用 node js express 应用程序。 Having admin side and user side.有管理端和用户端。 I have used socket io to send alert to the admin whenever a user places an order.每当用户下订单时,我都使用套接字 io 向管理员发送警报。 after doing load balancing using Nginx, only alerts are showing sometimes.使用 Nginx 进行负载平衡后,有时只显示警报。 I understand that it is because the user and admin are connected to different instances (amazon ec2).我知道这是因为用户和管理员连接到不同的实例(亚马逊 ec2)。 alerts send to admin only when both are in the same instance(amazon ec2).仅当两者位于同一实例(亚马逊 ec2)中时,警报才会发送给管理员。 what is the better solution to use socket io in this scenario?[socket io connection with express ][1]在这种情况下使用套接字 io 的更好解决方案是什么?[套接字 io 与 express 连接][1]

nginx configuration for load balancing nginx 配置负载均衡

In browser, console shows the following: failed: WebSocket is closed before the connection is established.在浏览器中,控制台显示如下: failed: WebSocket 在建立连接之前关闭。 status code: 400状态码:400

I'm not sure I got it clear but I do configuration like this我不确定我是否清楚,但我做了这样的配置

upstream socket {
     ip_hash;
     server localhost:xxxx; // your instance port
}

I decide to create socket path like: { path:"/user-socket" } inside socket configurations我决定在套接字配置中创建如下套接字路径:{ path:"/user-socket"}

location /user-socket {
    proxy_pass http://socket;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM