AWS Elastic Beanstalk 504网关超时 [英] AWS Elastic Beanstalk 504 Gateway Timeout
问题描述
我有一个在AWS Elastic Beanstalk上运行的Node服务器.我的一个端点接受了巨大的有效负载,并且该函数本身非常慢且冗长,并且可能需要10分钟以上的时间.
I have a Node server running on AWS Elastic Beanstalk. One of my endpoints accepts a huge payload and the function itself is pretty slow and lengthy, and can take upwards of 10+ minutes.
由于业务需求,它必须保留为单个HTTP POST,并且不能拆分成更小的任何内容.
Due to business requirements it must remain as a single HTTP POST and cannot be split up to be any smaller.
在较大的通话中,我收到504网关超时,始终在60秒左右.我尝试使用Elastic Beanstalk负载均衡器部分中的超时设置无济于事,看来最长的超时时间还是60秒.
On larger calls I am getting a 504 GATEWAY TIMEOUT, always around the 60 second mark. I have tried toying with the timeout settings in Elastic Beanstalk Load Balancer section to no avail, it seems the longest timeout duration is 60 second anyway.
我确实在 https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/config-idle-timeout.html
为确保冗长的操作(例如文件上传)有时间完成,请在每个空闲超时时间过去之前发送至少1个字节的数据
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
这听起来确实是我所需要的,但是我不知道该怎么完成
This sounds like exactly what I need, but I do not know how to accomplish
1)如何从Node应用程序发送至少1个字节的数据",以确保会话保持活动状态,并且在一分钟后不会超时
1) How can I "send at least 1 byte of data" from my Node app to ensure the session is kept alive and doesn't timeout after one minutes
推荐答案
504可以通过设置ELB策略来解决ElasticBeanstalk环境中的超时问题.可能还需要更新Nginx超时配置.
504 Timeouts on ElasticBeanstalk environments can be resolved by settings your ELB policies. Updating Nginx timeout configurations may also be required.
-
ELB策略:将Elastic Load Balancer的空闲超时设置为您选择的值(默认为60s).为此,请在项目的根目录中创建一个 .ebextensions 文件夹.在此文件夹中,创建另一个文件扩展名为 .config 的文件,并将ELB空闲超时设置为您选择的值(例如300秒):
ELB policies: Set the Idle Timeout of your Elastic Load Balancer to the value of your choice (defaults to 60s). To do this, create a .ebextensions folder in the root of your project. In this folder create another file with a .config file extension, and set the ELB Idle Timeout to the value of your choice (e.g. 300 seconds):
option_settings:
- namespace: aws:elb:policies
option_name: ConnectionSettingIdleTimeout
value: 300
或者,如果您使用的是应用程序负载平衡器:
Or if you are using an application load balancer:
option_settings:
- namespace: aws:elbv2:loadbalancer
option_name: IdleTimeout
value: 300
Nginx配置:将Nginx和设置为所需的超时值:send_timeout
,proxy_connect_timeout
,proxy_read_timeout, proxy_Send_timeout
全部默认为60s(要检查的其他规格可能是:client_header_timeout
,client_body_timeout
, keepalive_timeout
). Nginx中的默认超时值在规范中指定和配置文件(例如/etc/nginx
下的 .config 文件).在.ebextensions
文件夹中创建一个新文件(或在上面的.config文件中更新),并将以下内容附加到该文件内(根据观察到的超时添加或删除相关设置):
Nginx configuration: Set Nginx the with the desired value of timeout: send_timeout
, proxy_connect_timeout
, proxy_read_timeout, proxy_Send_timeout
all default to 60s (additional specification to check may be: client_header_timeout
, client_body_timeout
, keepalive_timeout
). Default timeout values in Nginx are specified in the specifications and configurations files (e.g. the .config files under /etc/nginx
). In the .ebextensions
folder create a new file (or update in the .config file above), and append the following content inside the file (add or remove relevant settings according to the timeouts observed):
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"
There are several more ways to add this configuration. Read more here and here.
编辑(06/11/2020):
一些用户指出keep_alive 300;
配置破坏了他们的服务器.因此,我已将其从nginx.custom.conf
配置中删除.
Edit (06/11/2020):
Some users indicated that the keep_alive 300;
configuration crushed their server. Therefore, I've removed that from the nginx.custom.conf
configuration.
这篇关于AWS Elastic Beanstalk 504网关超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!