使用 uwsgi 自动将 Nginx 配置为 运行 flask

configuring Nginx to run flask automatically with uwsgi

我正在开发 python 程序,我有一个烧瓶文件 运行。现在我正在尝试从 Nginx 自动 运行 flask 并使用 uWSGI linking 它们。它不起作用并且卡住了。

我跟着这个page.here是link:https://vladikk.com/2013/09/12/serving-flask-with-nginx-on-ubuntu/ 我已执行所有必要步骤并收到 502 bad gateway 错误。 执行时

uswgi  --ini /var/www/tg/tg_uswgi.ini

我得到以下信息

[uSWGI] getting INI configuration from /var/www/tg/tg_uwsgi.ini

在此之后,我没有得到 anything.when 我的 运行 我的服务器,它仍然给我 502 Bad gateway。

这是我的 tg_nginx.conf

server {
    listen      80;
    server_name localhost;
    charset     utf-8;
    client_max_body_size 75M;

    location / { try_files $uri @yourapplication; }
    location @yourapplication {
        include uwsgi_params;
        uwsgi_pass unix:/var/www/tg/tg_uwsgi.sock;
    }    
}

这是我的tg_uwsgi.ini

[uwsgi]
#application's base folder
base = /var/www/tg

#python module to import
app = fileforflk     //fileforflk is my flask file which calls other python 
                    //files
module = %(app)

home = %(base)/venv
pythonpath = %(base)

#socket file's location
socket = /var/www/demoapp/%n.sock

#permissions for the socket file
chmod-socket    = 666

#the variable that holds a flask application inside the module imported at line #6
callable = app

#location of log files
logto = /var/log/uwsgi/%n.log

这是我的烧瓶文件

from flask import Flask
import browser          //python file the flask is calling
app = Flask(_name_)
@app.route('/test',methods= ['GET'])
def result():
   return ("success")
if _name_ == '_main_':
   app.run(host = '0.0.0.0',port=5000)

获取 INI 配置后,终端没有显示任何内容,服务器仍然 returns 网关错误。请帮我解决这个问题。

您应该定义:

socket = /var/www/demoapp/%n.sock

并且:

uwsgi_pass unix:/var/www/tg/tg_uwsgi.sock;

应该匹配。例如,定义:

socket = /var/www/tg/%n.sock

并且:

sudo chown -R www-data:www-data /var/www/tg/
sudo chown -R www-data:www-data /var/log/uwsgi/