昨天,我在 Amazon Elastic Beanstalk 上部署了我的第一个 Flask 应用程序。 应用程序正在运行,但是当我按下启动抓取过程的按钮时出现问题。 这个过程很长,大约需要 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
你知道如何解决这个问题吗? 提前致谢
最佳答案
您尝试使用的 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;
关于amazon-web-services - AWS - 错误 504 - 网关超时 - Flask 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65475499/