AWS - 错误 504 - 网关超时 - Flask 应用程序

Posted

技术标签:

【中文标题】AWS - 错误 504 - 网关超时 - Flask 应用程序【英文标题】:AWS - Error 504 - Gateway timeout - Flask Application 【发布时间】:2021-04-05 02:24:13 【问题描述】:

昨天我在 Amazon Elastic Beanstalk 上部署了我的第一个烧瓶应用程序。 应用程序正在运行,但是当我按下启动抓取过程的按钮时出现问题。 这个过程很长,大概需要 3/4 分钟,很明显,在我按下按钮一分钟后,我得到了 504 错误。

我在互联网上阅读了很多关于如何解决这个问题的内容,它与 nginx 相关,但没有任何效果。

这是我尝试过的:

1. EC2 负载均衡器 我创建了一个连接到我的 istance 的负载均衡器,并将空闲超时增加到 300 秒。但什么都没有改变。

2。在我的项目中添加了 .ebextensions 我还尝试使用 my_name.conf 修改 nginx 参数

.ebextensions -> nginx -> conf.d -> my_name.conf

my_name.conf

keepalive_timeout 240s
proxy_read_timeout 240s;
proxy_send_timeout 240s;
proxy_connect_timeout 240s;

单独在.ebextensions

proxy.config

container_commands:
    01_reload_nginx:
        command: 'sudo service nginx reload'

这个解决方案都不起作用。

所以我尝试了另一种方法

.ebextensions我创建了这个文件,但没有用,然后我尝试输入.ebextensions -> nginx,但问题仍然存在。

proxy.config

files:
    “/etc/nginx/conf.d/01-timeout.conf”:
        mode: “000644”
        owner: root
        group: root
        content: |
            keepalive_timeout 240s;
            proxy_connect_timeout 240s;
            proxy_send_timeout 240s;
            proxy_read_timeout 240s;
            fastcgi_send_timeout 240s;
            fastcgi_read_timeout 240s;
container_commands:
    nginx_reload:
        command: “sudo service nginx reload”

我的项目结构是:

my_app
-> .ebextensions
->project (where there are python file with all the code)
->application.py (python file wiith main used to load all the file and launch the app)
->requirements.txt

你知道如何解决这个问题吗? 提前致谢

【问题讨论】:

是否可以通过设置以某种方式更改空闲超时?因为我不想手动配置它 【参考方案1】:

您尝试使用的 nginx 设置 (/etc/nginx/conf.d/01-timeout.conf`) 适用于 Amazon Linux 1

您可能正在使用 Amazon Linux 2,其 nginx 设置应在 .platform/nginx/conf.d/ 中,而不是在 .ebextentions 中(请参阅 docs)。

因此,您可以尝试以下.platform/nginx/conf.d/mytimeout.conf 的内容:

keepalive_timeout 240s;
proxy_connect_timeout 240s;
proxy_send_timeout 240s;
proxy_read_timeout 240s;
fastcgi_send_timeout 240s;
fastcgi_read_timeout 240s;

【讨论】:

天哪,伙计,你成就了我的一天。我真的很感谢你,我的坏,但我没有很好地搜索,我没有找到那个页面。再次感谢@Marcin

以上是关于AWS - 错误 504 - 网关超时 - Flask 应用程序的主要内容,如果未能解决你的问题,请参考以下文章

AWS Elastic Beanstalk 504 网关超时

phpMyAdmin 错误 504 网关超时重新加载

增加 504 超时错误

504 网关超时媒体寺

Django+Nginx+uWSGI = 504 网关超时

连接 Facebook Graph API 时 ElasticBeanstalk for PHP 上的 504 网关超时