简体   繁体   English

将Websocket与弹性beantalk,nginx和node.js一起使用时出现问题

[英]Issue using websocket with elastic beanstalk, nginx and node.js

I'm trying to deploy node.js application with sock.js on EB. 我正在尝试在EB上使用sock.js部署node.js应用程序。 Websockets work fine without proxy. Websockets无需代理即可正常工作。 When using nginx proxy ws connection issue occured. 使用Nginx代理时,出现ws连接问题。 I have apended .ebextensions/.config file: 我已经添加了.ebextensions / .config文件:

files:
  "/etc/nginx/conf.d/wssproxy.conf":
    mode: "000644"
    owner: root
    content: |
      map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
      }
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;

Websockets don't work, but nginx error log says: Websockets不起作用,但是nginx错误日志显示:

upstream prematurely closed connection while reading upstream, client: 83.219.138.215, server: , request: "POST x/XXXXX/432/2l4e2j6v/xhr_streaming HTTP/1.1", upstream: " http://xxx.0.0.1:8081/XXXXX/432/2l4e2j6v/xhr_streaming ", host: "XXXXXX.elasticbeanstalk.com", referrer: " http://XXXXXX.elasticbeanstalk.com/ " 上游过早关闭连接,同时读取上游,客户端:83.219.138.215,服务器:,请求:“ POST x / XXXXX / 432 / 2l4e2j6v / xhr_streaming HTTP / 1.1”,上游:“ http://xxx.0.0.1:8081 / XXXXX / 432 / 2l4e2j6v / xhr_streaming “,主机:” XXXXXX.elasticbeanstalk.com“,引荐来源网址:” http://XXXXXX.elasticbeanstalk.com/

This is likely due to the fact that your load balancer is not deterministically mapping requests to upstream servers on both layer 7 (HTTP) and layer 4 (websockets). 这可能是由于您的负载均衡器未确定地将请求映射到第7层(HTTP)和第4层(websockets)上的上游服务器。 You'll notice that your provided error message shows you're using xhr-streaming, which works on layer 7. I'm guessing that if you force just the websocket protocol or just HTTP polling these errors will become more consistent, but they wont go away. 您会注意到,您提供的错误消息显示您正在使用xhr-streaming,该功能适用​​于第7层。我猜测如果仅强制执行websocket协议或HTTP轮询,这些错误将变得更加一致,但它们不会走开。

Here's a more detailed explanation with a few possible solutions. 这是带有一些可能解决方案的更详细的说明。 Unfortunately, they're all pretty annoying to implement. 不幸的是,它们都非常讨厌实施。 The following question refers to socket.io, but since you're using sockjs the ideal solution is quite a bit easier to implement given sockjs' use of server-specific IDs in HTTP polling request paths . 以下问题是针对socket.io的,但是由于您正在使用sockjs,因此, 鉴于sockjs在HTTP轮询请求路径中使用服务器特定的ID的情况,理想的解决方案要容易得多

Node socket.io on load balanced Amazon EC2 负载均衡Amazon EC2上的节点socket.io

All of these problems would go away if it were possible to use a deterministic load balancing method on the ELB, such as IP or HTTP path hashing. 如果可以在ELB上使用确定性负载平衡方法(例如IP或HTTP路径哈希),所有这些问题都将消失。

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

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