Move others.rst to wsgi-standalone.rst.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Ron DuPlain · committed by Ron DuPlain · parent c269841 · Browse files · 2 files·+102 added−102 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+102 added−102 removed
- other:+102 added−102 removed
Provenance
- Commit
7e4b705- Tree
d72852b- Author
Ron DuPlain <ron.duplain@gmail.com>- Committer
Ron DuPlain <ron.duplain@gmail.com>- Parent
c269841
2 files changed+102 added−102 removed
deleted:docs/deploying/others.rst-102 removed
1-.. _deploying-other-servers:2-3-Other Servers4-=============5-6-There are popular servers written in Python that allow the execution of WSGI7-applications as well. These servers stand alone when they run; you can proxy8-to them from your web server.9-10-Tornado11---------12-13-`Tornado`_ is an open source version of the scalable, non-blocking web14-server and tools that power `FriendFeed`_. Because it is non-blocking and15-uses epoll, it can handle thousands of simultaneous standing connections,16-which means it is ideal for real-time web services. Integrating this17-service with Flask is a trivial task::18-19- from tornado.wsgi import WSGIContainer20- from tornado.httpserver import HTTPServer21- from tornado.ioloop import IOLoop22- from yourapplication import app23-24- http_server = HTTPServer(WSGIContainer(app))25- http_server.listen(5000)26- IOLoop.instance().start()27-28-29-.. _Tornado: http://www.tornadoweb.org/30-.. _FriendFeed: http://friendfeed.com/31-32-Gevent33--------34-35-`Gevent`_ is a coroutine-based Python networking library that uses36-`greenlet`_ to provide a high-level synchronous API on top of `libevent`_37-event loop::38-39- from gevent.wsgi import WSGIServer40- from yourapplication import app41-42- http_server = WSGIServer(('', 5000), app)43- http_server.serve_forever()44-45-.. _Gevent: http://www.gevent.org/46-.. _greenlet: http://codespeak.net/py/0.9.2/greenlet.html47-.. _libevent: http://monkey.org/~provos/libevent/48-49-Gunicorn50---------51-52-`Gunicorn`_ 'Green Unicorn' is a WSGI HTTP Server for UNIX. It's a pre-fork53-worker model ported from Ruby's Unicorn project. It supports both `eventlet`_54-and `greenlet`_. Running a Flask application on this server is quite simple::55-56- gunicorn myproject:app57-58-`Gunicorn`_ provides many command-line options -- see ``gunicorn -h``.59-For example, to run a Flask application with 4 worker processes (``-w60-4``) binding to localhost port 4000 (``-b 127.0.0.1:4000``)::61-62- gunicorn -w 4 -b 127.0.0.1:4000 myproject:app63-64-.. _Gunicorn: http://gunicorn.org/65-.. _eventlet: http://eventlet.net/66-.. _greenlet: http://codespeak.net/py/0.9.2/greenlet.html67-68-Proxy Setups69-------------70-71-If you deploy your application using one of these servers behind an HTTP72-proxy you will need to rewrite a few headers in order for the73-application to work. The two problematic values in the WSGI environment74-usually are `REMOTE_ADDR` and `HTTP_HOST`. Werkzeug ships a fixer that75-will solve some common setups, but you might want to write your own WSGI76-middleware for specific setups.77-78-The most common setup invokes the host being set from `X-Forwarded-Host`79-and the remote address from `X-Forwarded-For`::80-81- from werkzeug.contrib.fixers import ProxyFix82- app.wsgi_app = ProxyFix(app.wsgi_app)83-84-Please keep in mind that it is a security issue to use such a middleware85-in a non-proxy setup because it will blindly trust the incoming86-headers which might be forged by malicious clients.87-88-If you want to rewrite the headers from another header, you might want to89-use a fixer like this::90-91- class CustomProxyFix(object):92-93- def __init__(self, app):94- self.app = app95-96- def __call__(self, environ, start_response):97- host = environ.get('HTTP_X_FHOST', '')98- if host:99- environ['HTTP_HOST'] = host100- return self.app(environ, start_response)101-102- app.wsgi_app = CustomProxyFix(app.wsgi_app)added:docs/deploying/wsgi-standalone.rst+102 added
1+.. _deploying-other-servers:2+3+Other Servers4+=============5+6+There are popular servers written in Python that allow the execution of WSGI7+applications as well. These servers stand alone when they run; you can proxy8+to them from your web server.9+10+Tornado11+--------12+13+`Tornado`_ is an open source version of the scalable, non-blocking web14+server and tools that power `FriendFeed`_. Because it is non-blocking and15+uses epoll, it can handle thousands of simultaneous standing connections,16+which means it is ideal for real-time web services. Integrating this17+service with Flask is a trivial task::18+19+ from tornado.wsgi import WSGIContainer20+ from tornado.httpserver import HTTPServer21+ from tornado.ioloop import IOLoop22+ from yourapplication import app23+24+ http_server = HTTPServer(WSGIContainer(app))25+ http_server.listen(5000)26+ IOLoop.instance().start()27+28+29+.. _Tornado: http://www.tornadoweb.org/30+.. _FriendFeed: http://friendfeed.com/31+32+Gevent33+-------34+35+`Gevent`_ is a coroutine-based Python networking library that uses36+`greenlet`_ to provide a high-level synchronous API on top of `libevent`_37+event loop::38+39+ from gevent.wsgi import WSGIServer40+ from yourapplication import app41+42+ http_server = WSGIServer(('', 5000), app)43+ http_server.serve_forever()44+45+.. _Gevent: http://www.gevent.org/46+.. _greenlet: http://codespeak.net/py/0.9.2/greenlet.html47+.. _libevent: http://monkey.org/~provos/libevent/48+49+Gunicorn50+--------51+52+`Gunicorn`_ 'Green Unicorn' is a WSGI HTTP Server for UNIX. It's a pre-fork53+worker model ported from Ruby's Unicorn project. It supports both `eventlet`_54+and `greenlet`_. Running a Flask application on this server is quite simple::55+56+ gunicorn myproject:app57+58+`Gunicorn`_ provides many command-line options -- see ``gunicorn -h``.59+For example, to run a Flask application with 4 worker processes (``-w60+4``) binding to localhost port 4000 (``-b 127.0.0.1:4000``)::61+62+ gunicorn -w 4 -b 127.0.0.1:4000 myproject:app63+64+.. _Gunicorn: http://gunicorn.org/65+.. _eventlet: http://eventlet.net/66+.. _greenlet: http://codespeak.net/py/0.9.2/greenlet.html67+68+Proxy Setups69+------------70+71+If you deploy your application using one of these servers behind an HTTP72+proxy you will need to rewrite a few headers in order for the73+application to work. The two problematic values in the WSGI environment74+usually are `REMOTE_ADDR` and `HTTP_HOST`. Werkzeug ships a fixer that75+will solve some common setups, but you might want to write your own WSGI76+middleware for specific setups.77+78+The most common setup invokes the host being set from `X-Forwarded-Host`79+and the remote address from `X-Forwarded-For`::80+81+ from werkzeug.contrib.fixers import ProxyFix82+ app.wsgi_app = ProxyFix(app.wsgi_app)83+84+Please keep in mind that it is a security issue to use such a middleware85+in a non-proxy setup because it will blindly trust the incoming86+headers which might be forged by malicious clients.87+88+If you want to rewrite the headers from another header, you might want to89+use a fixer like this::90+91+ class CustomProxyFix(object):92+93+ def __init__(self, app):94+ self.app = app95+96+ def __call__(self, environ, start_response):97+ host = environ.get('HTTP_X_FHOST', '')98+ if host:99+ environ['HTTP_HOST'] = host100+ return self.app(environ, start_response)101+102+ app.wsgi_app = CustomProxyFix(app.wsgi_app)