amazon-web-services - AWS Elastic Beanstalk 504 网关超时

标签 amazon-web-services amazon-elastic-beanstalk

我有一个在 AWS Elastic Beanstalk 上运行的节点服务器。我的一个端点接受了一个巨大的有效负载,并且该函数本身非常缓慢且冗长,可能需要超过 10 分钟。

由于业务需求,它必须保留为单个 HTTP POST,并且不能拆分为更小。

在较大的调用中,我得到一个 504 GATEWAY TIMEOUT,总是在 60 秒左右。我曾尝试在 Elastic Beanstalk 负载均衡器部分玩弄超时设置,但无济于事,看来最长的超时持续时间是 60 秒。

我确实在 https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/config-idle-timeout.html 的文档中看到了一个有希望的解决方案

To ensure that lengthy operations such as file uploads have time to complete, send at least 1 byte of data before each idle timeout period elapses



这听起来正是我需要的,但我不知道如何完成

1) 如何从我的 Node 应用程序“发送至少 1 个字节的数据”以确保 session 保持事件状态并且在一分钟后不会超时

最佳答案

ElasticBeanstalk 环境中的 504 超时可以通过设置 ELB 策略来解决。可能还需要更新 Nginx 超时配置。

  • ELB 策略:将弹性负载均衡器的空闲超时设置为您选择的值(默认为 60 秒)。为此,请在项目的根目录中创建一个 .ebextensions 文件夹。在此文件夹中创建另一个文件扩展名为 .config 的文件,并将 ELB Idle Timeout 设置为您选择的值(例如 300 秒):
     option_settings:
       - namespace: aws:elb:policies
         option_name: ConnectionSettingIdleTimeout
         value: 300
    
    或者,如果您使用的是应用程序负载均衡器:
     option_settings:
       - namespace: aws:elbv2:loadbalancer
         option_name: IdleTimeout
         value: 300
    
  • Nginx 配置:将 Nginx 设置为所需的超时值:send_timeout , proxy_connect_timeout , proxy_read_timeout, proxy_Send_timeout所有默认为 60 秒(要检查的其他规范可能是:client_header_timeoutclient_body_timeoutkeepalive_timeout)。 Nginx 中的默认超时值在 specifications 中指定。和配置文件(例如 /etc/nginx 下的 .config 文件)。在 .ebextensions文件夹创建一个新文件(例如01-nginx-configuration.config或在上面的.config文件中更新),并在文件中附加以下内容(根据观察到的超时添加或删除相关设置):
     files:
       "/etc/nginx/conf.d/nginx.custom.conf":
           mode: "644"
           owner: "root"
           group: "root"
           content: |
             client_header_timeout   300;
             client_body_timeout     300;
             send_timeout            300;
             proxy_connect_timeout   300;
             proxy_read_timeout      300;
             proxy_send_timeout      300;
    
     container_commands:
       01_restart_nginx:
         command: "sudo service nginx reload"
    

  • 还有其他几种方法可以添加此配置。阅读更多 herehere .
    编辑(2020 年 6 月 11 日):
    有人表示keep_alive 300;配置粉碎了他们的服务器。因此,我已将其从 nginx.custom.conf 中删除。配置。

    关于amazon-web-services - AWS Elastic Beanstalk 504 网关超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49137188/

    相关文章:

    powershell - AWS - 在实例上使用 PowerShell 假设 IAM

    amazon-web-services - 无法以正确的形式在Hive表中加载数据

    amazon-web-services - 使用 Elastic Beanstalk .ebextensions 指定 RDS 数据库

    amazon-web-services - 将 .config 文件传递​​给 AWS Elastic Beanstalk

    node.js - create-react-app 构建过程花费的时间太长

    git - aws.push 不起作用

    c# - 使用 EC2 上运行的 C# 控制台应用程序连接到雪花时出现问题

    ruby-on-rails - Rack-cors 未在 swagger-ui_rails 的生产环境中显示 header

    node.js - AWS Elastic Beanstalk 中的 pm2 重启循环( Node 环境)

    amazon-elastic-beanstalk - Elastic Beanstalk : Migrate DB Security Group to VPC Security Group