Skip to content
Myr

uwsgi.rst

This file

Path

docs/deploying/uwsgi.rst

73 lines · 2.8 KiB

Last changed by

Merge pull request #3175 from singingwolfboy/fix-rst-line-too-longDavid Baumgoldbefore adoption819368a

History of this file

Take it

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

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 1–6why, one step back
1.. _deploying-uwsgi:
23uWSGI4=====56uWSGI is a deployment option on servers like `nginx`_, `lighttpd`_, and

Merge pull request #2861 from jwflory/fix/uwsgi-docsDavid Lordbefore adoption345685c

lines 7–10why, one step back
7`cherokee`_; see :doc:`fastcgi` and :doc:`wsgi-standalone` for other options.
8To use your WSGI application with uWSGI protocol you will need a uWSGI server9first. uWSGI is both a protocol and an application server; the application10server can serve uWSGI, FastCGI, and HTTP protocols.

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 11–12why, one step back
11
12The most popular uWSGI server is `uwsgi`_, which we will use for this

Merge pull request #2861 from jwflory/fix/uwsgi-docsDavid Lordbefore adoption345685c

line 13why, one step back
13guide. Make sure to have it installed to follow along.

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 14–33why, one step back
14
15.. 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:: text3132 $ uwsgi -s /tmp/yourapplication.sock --manage-script-name --mount /yourapplication=myapp:app33

Merge pull request #3175 from singingwolfboy/fix-rst-line-too-longDavid Baumgoldbefore adoption819368a

lines 34–38why, one step back
34The ``--manage-script-name`` will move the handling of ``SCRIPT_NAME``
35to uwsgi, since it is smarter about that.36It is used together with the ``--mount`` directive which will make37requests to ``/yourapplication`` be directed to ``myapp:app``.38If your application is accessible at root level, you can use a

Merge pull request #2861 from jwflory/fix/uwsgi-docsDavid Lordbefore adoption345685c

lines 39–42why, one step back
39single ``/`` instead of ``/yourapplication``. ``myapp`` refers to the name of
40the file of your flask application (without extension) or the module which41provides ``app``. ``app`` is the callable inside of your application (usually42the line reads ``app = Flask(__name__)``.

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 43–72why, one step back
43
44If you want to deploy your flask application inside of a virtual environment,45you need to also add ``--virtualenv /path/to/virtual/environment``. You might46also need to add ``--plugin python`` or ``--plugin python3`` depending on which47python version you use for your project.4849Configuring nginx50-----------------5152A basic flask nginx configuration looks like this::5354 location = /yourapplication { rewrite ^ /yourapplication/; }55 location /yourapplication { try_files $uri @yourapplication; }56 location @yourapplication {57 include uwsgi_params;58 uwsgi_pass unix:/tmp/yourapplication.sock;59 }6061This configuration binds the application to ``/yourapplication``. If you want62to have it in the URL root its a bit simpler::6364 location / { try_files $uri @yourapplication; }65 location @yourapplication {66 include uwsgi_params;67 uwsgi_pass unix:/tmp/yourapplication.sock;68 }6970.. _nginx: https://nginx.org/71.. _lighttpd: https://www.lighttpd.net/72.. _cherokee: http://cherokee-project.com/

Merge pull request #2969 from codeaditya/update-linksDavid Lordbefore adoption7e714bd

line 73why, one step back
73.. _uwsgi: https://uwsgi-docs.readthedocs.io/