我正在开发python程序,并且我有一个运行它们的flask文件。现在,我试图从Nginx自动运行flask,并将它们与uWSGI链接。它不起作用并且卡住了。
我关注了此页面。这里是链接:https://vladikk.com/2013/09/12/serving-flask-with-nginx-on-ubuntu/ 我已执行所有必要步骤,并收到502错误的网关错误。 执行时
uswgi --ini /var/www/tg/tg_uswgi.ini
我得到以下
[uSWGI] getting INI configuration from /var/www/tg/tg_uwsgi.ini
在此之后,我什么也没得到。当我运行服务器时,它仍然给我502错误的网关。
这是我的 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配置后,终端没有显示任何内容,并且服务器仍然返回错误的网关。请帮助我。
答案 0 :(得分:0)
您应该定义:
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/