uwsgi.rst
This file
Path
docs/deploying/uwsgi.rst
76 lines · 2.8 KiB
Last changed by
Merge pull request #1558 from JonasGroeger/masterArmin Ronacherbefore adoption751fe45
History of this fileTake it
The walk stopped after 200 commits: lines older than 8d3ee01 point at it.
Merge pull request #1132 from nicorevin/update_linksDaniel Neuhäuserbefore adoption8d3ee01
lines 1–31why, one step back1.. _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:: text31Merge pull request #1558 from JonasGroeger/masterArmin Ronacherbefore adoption751fe45
line 32why, one step back32 $ uwsgi -s /tmp/uwsgi.sock --manage-script-name --mount /yourapplication=myapp:appMerge pull request #1132 from nicorevin/update_linksDaniel Neuhäuserbefore adoption8d3ee01
lines 33–37why, one step back3334Or, if you prefer:3536.. sourcecode:: text37Merge pull request #1558 from JonasGroeger/masterArmin Ronacherbefore adoption751fe45
line 38why, one step back38 $ uwsgi -s /tmp/uwsgi.sock --manage-script-name --mount /yourapplication=myapp:appMerge pull request #1132 from nicorevin/update_linksDaniel Neuhäuserbefore adoption8d3ee01
line 39why, one step back39Merge pull request #1558 from JonasGroeger/masterArmin Ronacherbefore adoption751fe45
lines 40–51why, one step back40The ``--manage-script-name`` will move the handling of ``SCRIPT_NAME`` to41uwsgi, since its smarter about that. It is used together with the ``--mount``42directive which will make requests to ``/yourapplication`` be directed to43``myapp:app``, where ``myapp`` refers to the name of the file of your flask44application (without extension). ``app`` is the callable inside of your45application (usually the line reads ``app = Flask(__name__)``.4647If you want to deploy your flask application inside of a virtual environment,48you need to also add ``--virtualenv /path/to/virtual/environment``. You might49also need to add ``--plugin python`` or ``--plugin python3`` depending on which50python version you use for your project.51Merge pull request #1132 from nicorevin/update_linksDaniel Neuhäuserbefore adoption8d3ee01
lines 52–54why, one step back52Configuring nginx53-----------------54Merge pull request #1558 from JonasGroeger/masterArmin Ronacherbefore adoption751fe45
line 55why, one step back55A basic flask nginx configuration looks like this::Merge pull request #1132 from nicorevin/update_linksDaniel Neuhäuserbefore adoption8d3ee01
lines 56–60why, one step back5657 location = /yourapplication { rewrite ^ /yourapplication/; }58 location /yourapplication { try_files $uri @yourapplication; }59 location @yourapplication {60 include uwsgi_params;Merge pull request #1558 from JonasGroeger/masterArmin Ronacherbefore adoption751fe45
line 61why, one step back61 uwsgi_pass unix:/tmp/yourapplication.sock;Merge pull request #1132 from nicorevin/update_linksDaniel Neuhäuserbefore adoption8d3ee01
lines 62–63why, one step back62 }63Merge pull request #1240 from defuz/docs-style-fix-2Markus Unterwaditzerbefore adoption6fcc2ae
line 64why, one step back64This configuration binds the application to ``/yourapplication``. If you wantMerge pull request #1558 from JonasGroeger/masterArmin Ronacherbefore adoption751fe45
line 65why, one step back65to have it in the URL root its a bit simpler::Merge pull request #1132 from nicorevin/update_linksDaniel Neuhäuserbefore adoption8d3ee01
lines 66–69why, one step back6667 location / { try_files $uri @yourapplication; }68 location @yourapplication {69 include uwsgi_params;Merge pull request #1558 from JonasGroeger/masterArmin Ronacherbefore adoption751fe45
line 70why, one step back70 uwsgi_pass unix:/tmp/yourapplication.sock;Merge pull request #1132 from nicorevin/update_linksDaniel Neuhäuserbefore adoption8d3ee01
lines 71–76why, one step back71 }7273.. _nginx: http://nginx.org/74.. _lighttpd: http://www.lighttpd.net/75.. _cherokee: http://cherokee-project.com/76.. _uwsgi: http://projects.unbit.it/uwsgi/