Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Flask Nginx uWSGI 504网关超时错误_Python_Ubuntu_Nginx_Flask_Uwsgi - Fatal编程技术网

Python Flask Nginx uWSGI 504网关超时错误

Python Flask Nginx uWSGI 504网关超时错误,python,ubuntu,nginx,flask,uwsgi,Python,Ubuntu,Nginx,Flask,Uwsgi,我拼命想弄明白为什么我不能用uWSGI nginx和Ubuntu服务器部署我的flask应用程序 这是我在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, r

我拼命想弄明白为什么我不能用uWSGI nginx和Ubuntu服务器部署我的flask应用程序

这是我在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"
[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  
使用flask uWSGI和nginx设置好所有内容后,我就可以输入我的域名,然后进入我的网页(登录页面)。尝试登录时,页面暂停一段时间,然后我收到504网关超时

请告诉我该怎么做。这是我第一次部署应用程序,我花了大约一周的时间尝试不同的配置。我应该让您知道,我的flask应用程序通过ssh隧道连接到另一台服务器的数据库。不确定这是否也会导致此问题。如果可能的话,请帮助我,或者给我指出正确的方向

这是我的服务器块配置文件

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

    location / {                                                                                                                         
    include uwsgi_params;                                                                                                            
    uwsgi_pass unix:/home/pinchrep2/itinarep/itinarep.sock;                                                                          
}                                                                                                                                    
这是我的服务文件

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"
[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  
这是我的ini文件

[uwsgi]
module = wsgi:app

master = true
processes = 5

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

die-on-term=true 

有时,在部署带有库(如Keras和其他库)的flask应用程序时,它们在uWSGI中的线程方面存在一些问题

您可以在myproject.ini中更改一些内容以使其正常工作:

  • 在myproject.ini中添加这些设置

  • master=false能否发布Python脚本。问题可能就在那里@格温:嘿,谢谢你这么快就回来了。所以我的主python文件相当大。当我用python运行应用程序时,我能够进入我的服务器指定的公共ip和端口,并且能够很好地登录。在运行脚本uwsgi-socket 0.0.0.0:5000-protocol=http-wwsgi:app时,我也收到了相同的成功行为。python文件中是否有您想要查看的特定部分?我认为登录路径可能会超时,但情况似乎并非如此。你能把服务器绑定到套接字的部分贴出来吗?@gerwin不用担心。我遵循这个指南,我不确定哪一部分会绑定端口。我也完全不知道这件事。如果这些都没有帮助,很抱歉。你能获取服务的日志文件吗?也许有个错误。您可以使用journalctl获取它