1

我用flask appbuilder构建了一个web服务器,我可以通过命令运行这个项目:python3 run.py或fabmanage run,但是几个小时后没有交互时它总是没有响应,所以我尝试用Nginx运行它。

这是我的配置:

uwsgi.ini:

[uwsgi]
base = /root/flask_spider/gttx_spider/web
all_base = /root/flask_spider/gttx_spider/
app = run
module = %(app)
chdir = %(base)
virtualenv = %(all_base)/venv
socket = %(all_base)/uwsgi_gttx_spider.sock
logto = /var/log/uwsgi/%n.log
master = true
processes = 500
chmod-socket = 666
vacuum = true
callable = app

nginx.conf

server {
    listen      82;
    server_name gttx_spider;
    charset     utf-8;
    client_max_body_size 75M;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/root/flask_spider/gttx_spider/uwsgi_gttx_spider.sock;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
    }
}

并修改 run.py

from app import app

app.run(host='0.0.0.0')
#app.run(host='0.0.0.0', port=8080,debug=True)

接着:

sudo ln -s /root/flask_spider/gttx_spider/nginx.conf /etc/nginx/conf.d/
sudo /etc/init.d/nginx restart
uwsgi --ini uwsgi_gttx_spider.ini

当我访问 IP:82 并在 nginx 中获取此日志时:

[error] 11104#11104: *3 upstream timed out (110: Connection timed out) while reading response header from upstream

当我访问 IP:5000 时,这个登录 uwsgi:

2018-09-10 19:36:25,747:INFO:werkzeug: * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
2018-09-10 19:36:38,434:INFO:werkzeug:115.192.37.57 - - [10/Sep/2018 19:36:38] "GET / HTTP/1.1" 302 -
2018-09-10 19:36:38,466:INFO:werkzeug:115.192.37.57 - - [10/Sep/2018 19:36:38] "GET /home/ HTTP/1.1" 200 -

另外,我试试这个:
mv web/run.py web/run_bak.py
vi run.py

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8090)

并访问IP:82,它会返回'Hello World',一切都很好

不同的是werkzeug会在5000上运行flask appbuilder项目,以及如何在uwsgi.sock中运行,请帮忙,谢谢!

4

0 回答 0