用tornado将flask部署到Nginx上

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/AbeBetter/article/details/77652457

【flask_app.py】

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello Flask'

if __name__ == '__main__':
    app.run(debug=True)

【tornado_server.py】

#coding:utf8
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
# 导入flask项目
from flask_app import app

http_server = HTTPServer(WSGIContainer(app))
http_server.listen(5000)
IOLoop.current().start()

# 如果要开启多进程模式用下面的代码,不过仅在linux下
# http_server = HTTPServer(WSGIContainer(app))
# http_server.bind(8888)
# http_server.start(0)
# IOLoop.current().start()

【Nginx配置 nginx.conf】

server {
        listen       80;
        server_name  localhost;

        charset utf-8;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
            # 添加这句,指向tornado
            proxy_pass http://localhost:5000;
        }
展开阅读全文

没有更多推荐了,返回首页