Skip to content
Myr

uwsgi.rst

This file

Path

docs/deploying/uwsgi.rst

72 lines · 2.8 KiB

Last changed by

resolve merge conflictsKenneth Reitzbefore adoption31174fe

History of this file

Take it

The walk stopped after 200 commits: lines older than 817b72d point at it.

Removed deprecated module functionalityArmin Ronacherbefore adoption817b72d

lines 1–31why, one step back
1.. _deploying-uwsgi:
23uWSGI4=====56uWSGI is a deployment option on servers like `nginx`_, `lighttpd`_, and7`cherokee`_; see :ref:`deploying-fastcgi` and :ref:`deploying-wsgi-standalone`8for other options. To use your WSGI application with uWSGI protocol you will9need a uWSGI server first. uWSGI is both a protocol and an application server;10the application server can serve uWSGI, FastCGI, and HTTP protocols.1112The most popular uWSGI server is `uwsgi`_, which we will use for this13guide. Make sure to have it installed to follow along.1415.. admonition:: Watch Out1617 Please make sure in advance that any ``app.run()`` calls you might18 have in your application file are inside an ``if __name__ ==19 '__main__':`` block or moved to a separate file. Just make sure it's20 not called because this will always start a local WSGI server which21 we do not want if we deploy that application to uWSGI.2223Starting your app with uwsgi24----------------------------2526`uwsgi` is designed to operate on WSGI callables found in python modules.2728Given a flask application in myapp.py, use the following command:2930.. sourcecode:: text31

resolve merge conflictsKenneth Reitzbefore adoption31174fe

line 32why, one step back
32 $ uwsgi -s /tmp/yourapplication.sock --manage-script-name --mount /yourapplication=myapp:app

Removed deprecated module functionalityArmin Ronacherbefore adoption817b72d

line 33why, one step back
33

resolve merge conflictsKenneth Reitzbefore adoption31174fe

lines 34–41why, one step back
34The ``--manage-script-name`` will move the handling of ``SCRIPT_NAME`` to uwsgi,
35since its smarter about that. It is used together with the ``--mount`` directive36which will make requests to ``/yourapplication`` be directed to ``myapp:app``.37If your application is accessible at root level, you can use a single ``/``38instead of ``/yourapplication``. ``myapp`` refers to the name of the file of39your flask application (without extension) or the module which provides ``app``.40``app`` is the callable inside of your application (usually the line reads41``app = Flask(__name__)``.

Removed deprecated module functionalityArmin Ronacherbefore adoption817b72d

line 42why, one step back
42

resolve merge conflictsKenneth Reitzbefore adoption31174fe

lines 43–46why, one step back
43If you want to deploy your flask application inside of a virtual environment,
44you need to also add ``--virtualenv /path/to/virtual/environment``. You might45also need to add ``--plugin python`` or ``--plugin python3`` depending on which46python version you use for your project.

Removed deprecated module functionalityArmin Ronacherbefore adoption817b72d

lines 47–50why, one step back
47
48Configuring nginx49-----------------50

resolve merge conflictsKenneth Reitzbefore adoption31174fe

line 51why, one step back
51A basic flask nginx configuration looks like this::

Removed deprecated module functionalityArmin Ronacherbefore adoption817b72d

lines 52–56why, one step back
52
53 location = /yourapplication { rewrite ^ /yourapplication/; }54 location /yourapplication { try_files $uri @yourapplication; }55 location @yourapplication {56 include uwsgi_params;

resolve merge conflictsKenneth Reitzbefore adoption31174fe

line 57why, one step back
57 uwsgi_pass unix:/tmp/yourapplication.sock;

Removed deprecated module functionalityArmin Ronacherbefore adoption817b72d

lines 58–59why, one step back
58 }
59

Merge pull request #1240 from defuz/docs-style-fix-2Markus Unterwaditzerbefore adoption6fcc2ae

line 60why, one step back
60This configuration binds the application to ``/yourapplication``. If you want

resolve merge conflictsKenneth Reitzbefore adoption31174fe

line 61why, one step back
61to have it in the URL root its a bit simpler::

Removed deprecated module functionalityArmin Ronacherbefore adoption817b72d

lines 62–65why, one step back
62
63 location / { try_files $uri @yourapplication; }64 location @yourapplication {65 include uwsgi_params;

resolve merge conflictsKenneth Reitzbefore adoption31174fe

line 66why, one step back
66 uwsgi_pass unix:/tmp/yourapplication.sock;

Removed deprecated module functionalityArmin Ronacherbefore adoption817b72d

lines 67–68why, one step back
67 }
68

resolve merge conflictsKenneth Reitzbefore adoption31174fe

lines 69–70why, one step back
69.. _nginx: https://nginx.org/
70.. _lighttpd: https://www.lighttpd.net/

Removed deprecated module functionalityArmin Ronacherbefore adoption817b72d

lines 71–72why, one step back
71.. _cherokee: http://cherokee-project.com/
72.. _uwsgi: http://projects.unbit.it/uwsgi/