简体   繁体   English

Flask Nginx uWSGI 504 网关超时错误

[英]Flask Nginx uWSGI 504 Gateway Timeout Error

I'm desperately trying to figure out the issue of why I cannot deploy my flask application with uWSGI nginx and Ubuntu server.我拼命想弄清楚为什么我不能用 uWSGI nginx 和 Ubuntu 服务器部署我的烧瓶应用程序的问题。

Here is my error in nginx error log :这是我在nginx 错误日志中的错误

2019/05/12 09:00:19 [error] 10154#10154: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 24.27.57.18, server: itinareport.tk, request: "POST /login HTTP/1.1", upstream: "uwsgi://unix:/home/pinchrep2/itinarep/itinarep.sock", host: "www.itinareport.tk", referrer: "http://www.itinareport.tk/login"

Upon having everything setup with flask uWSGI and nginx I'm able to put my domain name in and it takes me to my web page (Login Page).在使用 Flask uWSGI 和 nginx 设置好所有内容后,我可以输入我的域名,然后它会将我带到我的网页(登录页面)。 Upon attempting to login the page pauses for some time and then I receive the 504 Gateway Time-Out尝试登录时页面暂停一段时间,然后我收到504 网关超时

Please advise me on what I should do.请建议我应该怎么做。 This is my first time ever deploying an application and it's been taking me about a week of trying different configurations.这是我第一次部署应用程序,我花了大约一周的时间尝试不同的配置。 I should have you know that I have my flask application connecting to a database through ssh tunnel to another server.我应该让您知道我的 Flask 应用程序通过 ssh 隧道连接到另一个服务器的数据库。 Not sure if that would cause this issue as well.不确定这是否也会导致此问题。 Please help if possible or point me in the right direction.如果可能,请提供帮助或为我指明正确的方向。

Here is my server block configuration file这是我的服务器块配置文件

server{
    listen 80;                                                                                                                           
    server_name itinareport.tk www.itinareport.tk;                                                                                       

    location / {                                                                                                                         
    include uwsgi_params;                                                                                                            
    uwsgi_pass unix:/home/pinchrep2/itinarep/itinarep.sock;                                                                          
}                                                                                                                                    

Here is my service file :这是我的服务文件

[Unit]                                                                                                                                  
Description=uWSGI instance to serve itinarep
After=network.target

[Service]
User=pinchrep2
Group=www-data
WorkingDirectory=/home/pinchrep2/itinarep
Environment="PATH=/home/pinchrep2/itinarep/it_venv/bin"
ExecStart=/home/pinchrep2/itinarep/it_venv/bin/uwsgi --ini itinarep.ini

[Install]
WantedBy=multi-user.target  

Here is my ini file这是我的ini文件

[uwsgi]
module = wsgi:app

master = true
processes = 5

socket = itinarep.sock
chmod-socket = 660
vacuum = true

die-on-term=true 

Sometimes when deploying a flask app with library like Keras and others they have some issue with threading in uWSGI.有时,在使用 Keras 等库部署 Flask 应用程序时,他们在 uWSGI 中遇到线程问题。

You can change a few things in myproject.ini to make it work:您可以在 myproject.ini 中更改一些内容以使其工作:

  1. add these setting in myproject.ini在 myproject.ini 中添加这些设置
master = false <-------- this
processes = 1 <--------- and this
  1. add cheaper = 0 to your myproject.ini添加cheaper = 0到您的 myproject.ini
  2. add lazy-apps = true to your myproject.inilazy-apps = true添加到您的 myproject.ini

So now your myproject.ini file may look like:所以现在你的 myproject.ini 文件可能看起来像:

[uwsgi]
module = wsgi:app

master = false <-------- this
processes = 1 <--------- and this
socket = myproject.sock
chmod-socket = 660
vacuum = true
die-on-term = true

cheaper = 0 <----------- also this, if option 1 is not enough or doesn't work

lazy-apps = true <------ in some case, this might help

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM