Nginx服务器上带有Gunicorn的Flask应用程序POST时出错

2024-06-10 17:10:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Python新手。我在EC2实例上托管了一个Flask应用程序,它将接受Gunicorn在Nginx服务器上的POST请求。在

当我在路线上发帖时,我的错误是:

1578#0: *14 upstream prematurely closed connection while reading response header from upstream, client: myip, server: serverip, request: "POST /train HTTP/1.1", upstream: "http://unix:/home/ec2-user/myproject/myproject.sock:/save_data", host: "serverip"

POST请求不是来自同一个域,并且总是来自其他域。我需要在我的nginx.conf公司文件?在

当我使用python命令运行应用程序时,一切都正常应用程序副本在


Tags: 实例服务器应用程序flaskmyproject错误nginxec2
1条回答
网友
1楼 · 发布于 2024-06-10 17:10:10

我能解决这个问题。这与我的NGINX配置无关(我最初认为这是原因)。在

这个问题存在于我的Gunicorn配置文件中。在

在我的Gunicorn配置文件(/etc/systemd/system/myproject.service)中,我在ExecStart行中添加了以下内容:

timeout 600

文件现在如下所示:

[Unit]
Description=Gunicorn instance to serve myproject
After=network.target

[Service]
User=harrison
Group=www-data
WorkingDirectory=/home/harrison/myproject
Environment="PATH=/home/harrison/myproject/myprojectenv/bin"
ExecStart=/home/harrison/myproject/myprojectenv/bin/gunicorn  workers 3  timeout 600  bind unix:myproject.sock -m 007 wsgi:application

[Install]
WantedBy=multi-user.target

此外,使用python app.py启动应用程序时没有遇到问题的原因是Gunicorn没有以这种方式提供服务。。。它正在使用Flask测试开发服务器。开发服务器的超时持续时间与Gunicorn不同。默认情况下,我相信Gunicorn超时默认为30秒。就我的申请而言,这个数字太低了。在

相关问题 更多 >