我有一个在 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 超时配置。
option_settings:
- namespace: aws:elb:policies
option_name: ConnectionSettingIdleTimeout
value: 300
或者,如果您使用的是应用程序负载均衡器: option_settings:
- namespace: aws:elbv2:loadbalancer
option_name: IdleTimeout
value: 300
send_timeout
, proxy_connect_timeout
, proxy_read_timeout, proxy_Send_timeout
所有默认为 60 秒(要检查的其他规范可能是:client_header_timeout
、client_body_timeout
、keepalive_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"
还有其他几种方法可以添加此配置。阅读更多 here和 here .
编辑(2020 年 6 月 11 日):
有人表示
keep_alive 300;
配置粉碎了他们的服务器。因此,我已将其从 nginx.custom.conf
中删除。配置。
关于amazon-web-services - AWS Elastic Beanstalk 504 网关超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49137188/