Skip to content
Myr

uwsgi.rst

This file

Path

docs/deploying/uwsgi.rst

68 lines · 2.2 KiB

Last changed by

Merge branch 'master' of github.com:mitsuhiko/flaskArmin Ronacherbefore adoptionf0c089f

History of this file

Take it

1.. _deploying-uwsgi:23uWSGI4=====56uWSGI is a deployment option on servers like `nginx`_, `lighttpd`_, and7`cherokee`_; see :ref:`deploying-fastcgi` and8:ref:`deploying-other-servers` for other options.  To use your WSGI9application with uWSGI protocol you will need a uWSGI server10first. uWSGI is both a protocol and an application server; the11application server can serve uWSGI, FastCGI, and HTTP protocols.1213The most popular uWSGI server is `uwsgi`_, which we will use for this14guide.  Make sure to have it installed to follow along.1516.. admonition:: Watch Out1718   Please make sure in advance that any ``app.run()`` calls you might19   have in your application file are inside an ``if __name__ ==20   '__main__':`` block or moved to a separate file.  Just make sure it's21   not called because this will always start a local WSGI server which22   we do not want if we deploy that application to uWSGI.2324Starting your app with uwsgi25----------------------------2627`uwsgi` is designed to operate on WSGI callables found in python modules.2829Given a flask application in myapp.py, use the following command:3031.. sourcecode:: text3233    $ uwsgi -s /tmp/uwsgi.sock --module myapp --callable app3435Or, if you prefer:3637.. sourcecode:: text3839    $ uwsgi -s /tmp/uwsgi.sock -w myapp:app4041Configuring nginx42-----------------4344A basic flask uWSGI configuration for nginx looks like this::4546    location = /yourapplication { rewrite ^ /yourapplication/; }47    location /yourapplication { try_files $uri @yourapplication; }48    location @yourapplication {49      include uwsgi_params;50      uwsgi_param SCRIPT_NAME /yourapplication;51      uwsgi_modifier1 30;52      uwsgi_pass unix:/tmp/uwsgi.sock;53    }5455This configuration binds the application to `/yourapplication`.  If you want56to have it in the URL root it's a bit simpler because you don't have to tell57it the WSGI `SCRIPT_NAME` or set the uwsgi modifier to make use of it::5859    location / { try_files $uri @yourapplication; }60    location @yourapplication {61        include uwsgi_params;62        uwsgi_pass unix:/tmp/uwsgi.sock;63    }6465.. _nginx: http://nginx.org/66.. _lighttpd: http://www.lighttpd.net/67.. _cherokee: http://www.cherokee-project.com/68.. _uwsgi: http://projects.unbit.it/uwsgi/