标签:flask tornado
1、Flask的入口措施为manage.py,代码如下:
#coding=utf-8#!/usr/bin/python
from somewhere import app #somewhere 暗示的包罗Flask的实例,如app = Flask(__name__) if __name__ == "__main__": app.run(debug=True)2、在manage.py的同级目录添加tornado应用措施tornado_server.py来托管manage.py,代码如下:
#coding=utf-8#!/usr/bin/python from tornado.wsgi import WSGIContainerfrom tornado.httpserver import HTTPServerfrom tornado.ioloop import IOLoopfrom run import app http_server = HTTPServer(WSGIContainer(app)) http_server.bind(5000, "0.0.0.0") # 对外开启访谒 http_server.start(1) # http_server.listen(5000) #或者只监听127.0.0.1的默认端口 IOLoop.instance().start()3.如果直接运行python tornado_server.py会正常运行,输出如下:
* Running on :5000/
* Restarting with reloader
但是在出产环境中得部署到性能好的nginx上,nginx配置如下:
server {
listen 80;
server_name abc.com;
rewrite ^(.*) $1 permanent;
}
server{
listen 80;
#listen [::]:80 default_server;
#access_log /var/log/nginx/win2003_access.log main;
#include header_proxy.inc;
server_name ;
#root /var/www/abc;
location / {
#index index.html index.htm index.php;
#include uwsgi_params;
#uwsgi_pass unix:/tmp/uwsgi.sock;
proxy_pass :5000; #关键一点就是这里,意思是所有对:80的访谒城市重定向到本机的5000端口上
}
}
另外一些优化好比静态文件暂没有让 nginx代办代理
配置好后只需要重载一下nginx 就可以生效:
Windows环境将Flask应用措施部署在tornado+nginx的简单要领
标签:flask tornado
,