AWS ElasticBeanStalk节点中的套接字Io [英] Socket Io in AWS ElasticBeanStalk Node

查看:72
本文介绍了AWS ElasticBeanStalk节点中的套接字Io的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Elastic Bean stalk中有一个node js应用程序.我们正在考虑将Socket io用于功能.

I have a node js application in Elastic Bean stalk.We are considering using socket io for a feature .

我在某些地方读到必须在AWS elasticbeanstalk中手动启用套接字io支持.特别是当它使用默认的NGINX代理时.

I read in some places that socket io support has to be manually enabled in AWS elasticbeanstalk. Specifically when it uses the default NGINX proxy.

我阅读默认情况下,一个弹性beantalk实例前面有一个nginx代理,该代理未配置为允许webSockets.

I read By default an elastic beanstalk instance has an nginx proxy in front of it that is not configured to allow webSockets.

这是正确的信息吗?如果是这样,如何在AWS EB中启用套接字io支持?

Is this correct information? If so , how to enable socket io support in AWS EB?

推荐答案

这是正确的信息.您需要为Elastic Beanstalk部署进行一些其他配置,以使WebSockets(Socket.io或其他方式)正常工作.

This is correct information. You'll need to do some additional configuration for your Elastic Beanstalk deployment to get WebSockets(Socket.io or otherwise) to work.

创建了Elastic Beanstalk环境后,您需要配置负载均衡器以接受TCP连接,并将配置文件添加到节点项目的根目录:

Once you create your Elastic Beanstalk Environment, you'll need to configure your load balancer to accept TCP connections, and add a configuration file to your node project's root directory:

配置负载均衡器:

  • 转到您的EC2控制台,然后选择"Load Balancers"选项卡
  • 从以下列表中选择属于您的ELB环境的负载均衡器 列表
  • 选择侦听器"标签
  • 将默认条目的实例协议更改为TCP
  • Head over to your EC2 console and select the Load Balancers tab
  • Select the load balancer that belongs to your ELB environment from the list
  • Select the Listeners tab
  • Change the default entries' Instance Protocol to TCP

添加配置文件:

  • 在节点项目的根目录中,创建一个名为 .ebextensions
  • In the root directory of your node project, create a folder called .ebextensions

在新的.ebextensions文件夹中创建一个名为enable-websockets.config的文件,其内容如下:

Create a file called enable-websockets.config in your new .ebextensions folder with the following contents:

container_commands:
  enable_websockets:
    command: |
      sed -i '/\s*proxy_set_header\s*Connection/c \
              proxy_set_header Upgrade $http_upgrade;\
              proxy_set_header Connection "upgrade";\
              proxy_pass_request_headers on;\
              ' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf

此文件告诉NGINX反向代理如何处理WebSockets与应用服务器通信所需的HTTP 101升级状态代码.

This file tells the NGINX reverse proxy how to handle the HTTP 101 upgrade status code that WebSockets need to communicate with your application server.

这篇关于AWS ElasticBeanStalk节点中的套接字Io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆