WebSocket Issue on AWS Elastic Beanstalk Using Port 80

后端 未结 1 1798
陌清茗
陌清茗 2021-02-04 20:56

I am migrating a node.js app from Heroku to AWS Elastic Beanstalk that uses WebSockets on port 80. The WebSockets are returning a 301 error on AWS Elastic Beanstalk, but not on

相关标签:
1条回答
  • 2021-02-04 21:34

    I found part of the answer here, https://scopestar.com/blog/aws/elasticbeanstalk/websockets/2016/10/21/enable-websockets-on-elasticbeanstalk-nginx-proxy.html

    I added a file in the .ebextensions folder with the following content and that fixed it for single instance environments.

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

    To get the WebSockets to work on the load balanced, auto scaling environment I needed to do the following in addition

    • Go to the EC2 Dashboard
    • Find the Load Balancer that the Elastic Beanstalk project created
    • Right click on the Load Balancer and click Edit listener
    • Change the Load Balancer Protocol from HTTP to TCP for port 80 and save changes
    0 讨论(0)
提交回复
热议问题