Elasticbeanstalk 返回“504 网关超时"; [英] Elasticbeanstalk returns "504 Gateway Timeout"

查看:48
本文介绍了Elasticbeanstalk 返回“504 网关超时";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 API 中有一个端点需要一些时间来返回响应(> 1 分钟).

I have an endpoint in my API which takes some time to return a response (>1 min).

我已将我的 API 部署到 Elasticbeanstalk,现在当我尝试访问它时,我收到了来自 Nginx 的 504 网关超时

I have deployed my API to Elasticbeanstalk and now when I try to access it I get a 504 Gateway Timeout from Nginx

<html>
<head><title>504 Gateway Time-out</title></head>
<body>
<center><h1>504 Gateway Time-out</h1></center>
</body>
</html>

我该如何解决?

推荐答案

像您这样的超时错误最好通过改进软件本身来解决,但如果由于任何原因无法完成,那么您可以增加您的超时nginx 和负载均衡器.

Timeout errors such as yours should ideally fixed by improvement to the software itself, but if it cannot be done for any reason, then you can increase the timeout of your nginx and Load Balancer.

在以前版本的 Amazon Linux 中,您需要在名为 .ebextensions 的目录中使用自定义 nginx 配置部署代码

In previous versions of Amazon Linux you would need to deploy your code with custom nginx configuration inside a directory named .ebextensions

对于 Amazon Linux 2,情况完全相同,但略有不同,您需要使用 .platform 文件夹来进行平台配置,而不是使用 .ebextensions.

With Amazon Linux 2 things are quite the same with a slight difference, instead of using the .ebextensions you need to use the .platform folder for your platform's configurations.

因此,在您的应用程序预期的 ElasticBeanstalk 包中创建以下结构 -

So, inside your app's intended ElasticBeanstalk package create the following structure -

eb-package
└── src
└── .ebextensions
└── .platform
    └── nginx
        └── conf.d
            └── timeout.conf

并将以下内容添加到您的 timeout.conf 文件中

And add the following content to your timeout.conf file

proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;

您应该知道,在某些情况下,您需要通过使用 AWS 控制台(在 EC2 下)手动配置负载均衡器或通过在 .ebextensions 目录

You should be aware that in some cases you'll need to increase your Load Balancer's timeout by either manually configuring it with the AWS Console (Under EC2) or by providing a configuration file inside the .ebextensions directory

例如(注意:此配置会因您使用的负载均衡器类型而异):

For example (Note: this configuration will vary by the type of Load Balancer which you use):

option_settings:
   - namespace: aws:elb:policies
     option_name: ConnectionSettingIdleTimeout
     value: 300

查看 Classic Load Balancer 与 Application Load Balancer 配置

See Classic Load Balancer vs Application Load Balancer configuration

在 AWS 的文档中(每 08/29/2021),较新的应用程序负载均衡器没有默认超时.Classic Load Balancer 的超时时间为 60 秒.

In AWS's docs (per 08/29/2021) the newer Application Load Balancer has no default timeout. The Classic Load Balancer has a timeout of 60 seconds.

aws:elb:policies对比aws:elbv2:loadbalancer

有关详细信息,请参阅

AWS 环境选项

这篇关于Elasticbeanstalk 返回“504 网关超时";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆