我有一个在 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 https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/config-idle-timeout.html
为确保文件上传等冗长操作有时间完成,请在每个空闲超时时间过去之前至少发送 1 个字节的数据
这听起来正是我所需要的,但我不知道如何实现
1)如何从我的 Node 应用程序“发送至少 1 个字节的数据”以确保会话保持活动状态并且在一分钟后不会超时
ElasticBeanstalk 环境中的 504 超时可以通过设置 ELB 策略来解决。可能还需要更新 Nginx 超时配置。
-
ELB 策略:将弹性负载均衡器的空闲超时设置为您选择的值(默认为 60 秒)。为此,请创建一个.eb扩展名项目根目录中的文件夹。在此文件夹中创建另一个文件.config文件扩展名,并将 ELB 空闲超时设置为您选择的值(例如 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_timeout
, client_body_timeout
, keepalive_timeout
)。 Nginx 中的默认超时值在规格 https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-nginx.html和配置文件(例如.config文件下/etc/nginx
)。在里面.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 https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-nginx.html and here https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-proxy.html.
编辑(2020年6月11日):
有人表示,keep_alive 300;
配置压垮了他们的服务器。因此,我已将其从nginx.custom.conf
配置。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)