How to deploy a Node.js WebSocket server to Amazon Elastic Beanstalk?

后端 未结 2 1366
花落未央
花落未央 2021-01-16 12:24

Using the Elastic Beanstalk web console, I\'ve launched a new Web Server 1.0 environment with:

  • Predefined configuration: Node.js, 64bit Amazon Linux 2014.09 v1
2条回答
  •  生来不讨喜
    2021-01-16 13:07

    Alright, after quite a bit or searching, I found a solution that works without changing anything to the ELB and without setting the proxy to none (I use nginx).

    All you need is this:

    • In the root of your project, create the .ebextensions directory (if it doesn't already exist)
    • Create a file in there, I called mine 01_nginx.config
    • In this file, put the following code: container_commands:

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

    Deploy your code to elastic beanstalk and enjoy websockets connecting!

    PS: You don't really need the proxy_read_timeout property set, I just use that for my own. Also, it doesn't seem to do much so, I'll keep looking.

提交回复
热议问题