我是Python的新手。我托管了Flask应用程序,它将在EC2实例上的Nginx服务器上接受Gunicorn的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 app.py命令运行应用程序时,一切运行正常
发布于 2018-06-01 03:45:02
我能够解决这个问题。这与我的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秒。在我的应用程序中,这个值太低了。
https://stackoverflow.com/questions/50612106
复制相似问题