Navigation

There are popular servers written in Python that contain WSGI applications and
serve HTTP. These servers stand alone when they run; you can proxy to them
from your web server. Note the section on Proxy Setups if you
run into issues.

Gunicorn ‘Green Unicorn’ is a WSGI HTTP Server for UNIX. It’s a pre-fork
worker model ported from Ruby’s Unicorn project. It supports both eventlet
and greenlet. Running a Flask application on this server is quite simple:

gunicornmyproject:app

Gunicorn provides many command-line options – see gunicorn-h.
For example, to run a Flask application with 4 worker processes (-w4) binding to localhost port 4000 (-b127.0.0.1:4000):

Twisted Web is the web server shipped with Twisted, a mature,
non-blocking event-driven networking library. Twisted Web comes with a
standard WSGI container which can be controlled from the command line using
the twistd utility:

twistdweb--wsgimyproject.app

This example will run a Flask application called app from a module named
myproject.

Twisted Web supports many flags and options, and the twistd utility does
as well; see twistd-h and twistdweb-h for more information. For
example, to run a Twisted Web server in the foreground, on port 8080, with an
application from myproject:

If you deploy your application using one of these servers behind an HTTP proxy
you will need to rewrite a few headers in order for the application to work.
The two problematic values in the WSGI environment usually are REMOTE_ADDR
and HTTP_HOST. You can configure your httpd to pass these headers, or you
can fix them in middleware. Werkzeug ships a fixer that will solve some common
setups, but you might want to write your own WSGI middleware for specific
setups.

Here’s a simple nginx configuration which proxies to an application served on
localhost at port 8000, setting appropriate headers: