用tornado將flask部署到Nginx上
阿新 • • 發佈:2019-01-07
【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;
}