1, Flask entrance program for manage.py, the code is as follows:
#coding =utf-8#!/usr/bin/python
The From somewhere Import app #somewhere represents an instance that contains Flask, such as App = Flask (__name__) If __name__ = = "__main__": App.run (debug=true )
2, add Tornado application tornado_server.py to host manage.py in manage.py's sibling directory, code as follows:
#coding =utf-8#!/usr/bin/pythonfrom tornado.wsgi Import wsgicontainerfrom tornado.httpserver import Httpserverfrom Tornado.ioloop Import ioloopfrom Run Import apphttp_server = Httpserver (Wsgicontainer (APP)) Http_server.bind (5000, " 0.0.0.0 ") # Open Access Http_server.start (1) # Http_server.listen (#或者只监听127) 0.0.1 default port Ioloop.instance (). Start ()
3. If running Python tornado_server.py will run normally, the output is as follows:
* Running on Http://127.0.0.1:5000/
* Restarting with Reloader
But in the production environment to be deployed to the performance of the Nginx, Nginx configuration is as follows:
server {
Listen 80;
server_name abc.com;
Rewrite ^ (. *) http://www.abc.com$1 permanent;
}
server{
Listen 80;
#listen [::]:80 default_server;
#access_log/var/log/nginx/win2003_access.log Main;
#include header_proxy.inc;
server_name www.abc.com;
#root/var/www/abc;
Location/{
#index index.html index.htm index.php;
#include uwsgi_params;
#uwsgi_pass Unix:/tmp/uwsgi.sock;
Proxy_pass http://localhost:5000; #关键一点就是这里 means that all access to HTTP://WWW.ABC.COM:80 is redirected to Port 5000 on this machine.
}
}
Some other optimizations, such as static files, do not let Nginx proxy
After configuration, only need to overload the Nginx can be effective:
A simple way for the Windows environment to deploy flask applications in Tornado+nginx