Socket Io in AWS ElasticBeanStalk Node

后端 未结 1 1367
余生分开走
余生分开走 2021-01-29 03:03

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

I read in some places that socket io support has to be manually ena

相关标签:
1条回答
  • 2021-01-29 03:51

    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.

    0 讨论(0)
提交回复
热议问题