Elastic Beanstalk 在配置菜单中没有负载均衡器设置

Posted

技术标签:

【中文标题】Elastic Beanstalk 在配置菜单中没有负载均衡器设置【英文标题】:Elastic Beanstalk has not load balancer setting in the configuration menu 【发布时间】:2018-04-23 07:06:11 【问题描述】:

我正在尝试在我的 Elastic Beanstalk 应用程序上启用 websocket,但在按照此处 (https://mitchellsimoens.com/websockets-behind-elastic-beanstalk/) 的说明进行操作后,我发现我的应用程序的运行状况已下降。这可能是因为我在本说明中提到的配置菜单中找不到负载均衡器设置。

这是我的配置菜单截图:

显然,websocket 不适用于我的应用程序。事实上,在我将.ebextensions/files.config 添加到我的项目后,整个应用程序都已关闭。当然,我的 process.env.PORT 是 80 而不是 3000(我想,不知道在哪里看)。

这两种设置我都试过了:

files:
  "/etc/nginx/conf.d/01_websockets.conf" :
    mode: "000644"
    owner: root
    group: root
    content : |
      upstream nodejs 
        server 127.0.0.1:process.env.PORT;
        keepalive 256;
      
      server 
        listen process.env.PORT;
        large_client_header_buffers 8 32k;
        location / 
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_set_header X-NginX-Proxy true;

          # prevents 502 bad gateway error
          proxy_buffers 8 32k;
          proxy_buffer_size 64k;

          proxy_pass http://nodejs;
          proxy_redirect off;

          # enables WS support
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
        
      

files:
  "/etc/nginx/conf.d/01_websockets.conf" :
    mode: "000644"
    owner: root
    group: root
    content : |
      upstream nodejs 
        server 127.0.0.1:80;
        keepalive 256;
      
      server 
        listen 80;
        large_client_header_buffers 8 32k;
        location / 
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_set_header X-NginX-Proxy true;

          # prevents 502 bad gateway error
          proxy_buffers 8 32k;
          proxy_buffer_size 64k;

          proxy_pass http://nodejs;
          proxy_redirect off;

          # enables WS support
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
        
      

【问题讨论】:

【参考方案1】:

Scaling > Single instance 类型 EB 没有负载平衡设置,但是您所做的几乎是正确的:

默认情况下,您需要监听 8080 而不是 80(AWS 就是这样令人困惑),并且需要将流量发送到您使用的任何端口,在本例中为 80,所以...

您还需要删除旧的 nginx_confg 并重新启动实例/服务器。

files:
  "/etc/nginx/conf.d/01_websockets.conf":
    mode: "000644"
    owner: root
    group: root
    content : |
      upstream nodejs 
        server 127.0.0.1:80;
        keepalive 256;
      
      server 
        listen 8080;
        large_client_header_buffers 8 32k;
        location / 
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_set_header X-NginX-Proxy true;

          # prevents 502 bad gateway error
          proxy_buffers 8 32k;
          proxy_buffer_size 64k;

          proxy_pass http://nodejs;
          proxy_redirect off;

          # enables WS support
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
        
      
  "/opt/elasticbeanstalk/hooks/appdeploy/enact/41_remove_eb_nginx_confg.sh":
    mode: "000755"
    owner: root
    group: root
    content : |
      mv /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf.old

【讨论】:

以上是关于Elastic Beanstalk 在配置菜单中没有负载均衡器设置的主要内容,如果未能解决你的问题,请参考以下文章

如何在 AWS Elastic Beanstalk 上修改 Nginx 配置

Elastic Beanstalk 滚动环境配置更新

AWS Elastic Beanstalk 中的 HTTPS 配置

在 Elastic Beanstalk 配置设置中拒绝访问 S3 对象

如何在 AWS Elastic Beanstalk 中更改数据库配置

Elastic Beanstalk,配置从未运行?