A simple way for the Windows environment to deploy flask applications in Tornado+nginx

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.