Socket Io in AWS ElasticBeanStalk Node

允我心安 提交于 2019-12-02 10:55:08

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.

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:

Configure Load Balancer:

  • 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

Add the Configuration File:

  • In the root directory of your node project, create a folder called .ebextensions

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!