uwsgi.rst
This file
Path
docs/deploying/uwsgi.rst
145 lines · 4.7 KiB
Last changed by
Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9
History of this fileTake it
The walk stopped after 200 commits: lines older than 48ee204 point at it.
Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
lines 1–3why, one step back1uWSGI2=====3Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 4–5why, one step back4`uWSGI`_ is a fast, compiled server suite with extensive configuration5and capabilities beyond a basic server.Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 6why, one step back6Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 7–11why, one step back7* It can be very performant due to being a compiled program.8* It is complex to configure beyond the basic application, and has so9 many options that it can be difficult for beginners to understand.10* It does not support Windows (but does run on WSL).11* It requires a compiler to install in some cases.Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 12why, one step back12Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 13–14why, one step back13This page outlines the basics of running uWSGI. Be sure to read its14documentation to understand what features are available.Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 15why, one step back15Merge branch '2.1.x'David Lordbefore adoption9139af1
line 16why, one step back16.. _uWSGI: https://uwsgi-docs.readthedocs.io/en/latest/Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
lines 17–18why, one step back1718Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 19–20why, one step back19Installing20----------Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 21why, one step back21Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 22–25why, one step back22uWSGI has multiple ways to install it. The most straightforward is to23install the ``pyuwsgi`` package, which provides precompiled wheels for24common platforms. However, it does not provide SSL support, which can be25provided with a reverse proxy instead.Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 26why, one step back26Merge branch '2.1.x'David Lordbefore adoption9139af1
line 27why, one step back27Create a virtualenv, install your application, then install ``pyuwsgi``.Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 28why, one step back28Merge branch '2.1.x'David Lordbefore adoption9139af1
line 29why, one step back29.. code-block:: textMerge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 30why, one step back30Merge branch '2.1.x'David Lordbefore adoption9139af1
line 31why, one step back31 $ cd hello-appMerge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9
lines 32–33why, one step back32 $ python -m venv .venv33 $ . .venv/bin/activateMerge branch '2.1.x'David Lordbefore adoption9139af1
lines 34–35why, one step back34 $ pip install . # install your application35 $ pip install pyuwsgiMerge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 36why, one step back36Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 37–39why, one step back37If you have a compiler available, you can install the ``uwsgi`` package38instead. Or install the ``pyuwsgi`` package from sdist instead of wheel.39Either method will include SSL support.Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 40why, one step back40Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 41–119why, one step back41.. code-block:: text4243 $ pip install uwsgi4445 # or46 $ pip install --no-binary pyuwsgi pyuwsgi474849Running50-------5152The most basic way to run uWSGI is to tell it to start an HTTP server53and import your application.5455.. code-block:: text5657 $ uwsgi --http 127.0.0.1:8000 --master -p 4 -w hello:app5859 *** Starting uWSGI 2.0.20 (64bit) on [x] ***60 *** Operational MODE: preforking ***61 mounting hello:app on /62 spawned uWSGI master process (pid: x)63 spawned uWSGI worker 1 (pid: x, cores: 1)64 spawned uWSGI worker 2 (pid: x, cores: 1)65 spawned uWSGI worker 3 (pid: x, cores: 1)66 spawned uWSGI worker 4 (pid: x, cores: 1)67 spawned uWSGI http 1 (pid: x)6869If you're using the app factory pattern, you'll need to create a small70Python file to create the app, then point uWSGI at that.7172.. code-block:: python73 :caption: ``wsgi.py``7475 from hello import create_app7677 app = create_app()7879.. code-block:: text8081 $ uwsgi --http 127.0.0.1:8000 --master -p 4 -w wsgi:app8283The ``--http`` option starts an HTTP server at 127.0.0.1 port 8000. The84``--master`` option specifies the standard worker manager. The ``-p``85option starts 4 worker processes; a starting value could be ``CPU * 2``.86The ``-w`` option tells uWSGI how to import your application878889Binding Externally90------------------9192uWSGI should not be run as root with the configuration shown in this doc93because it would cause your application code to run as root, which is94not secure. However, this means it will not be possible to bind to port9580 or 443. Instead, a reverse proxy such as :doc:`nginx` or96:doc:`apache-httpd` should be used in front of uWSGI. It is possible to97run uWSGI as root securely, but that is beyond the scope of this doc.9899uWSGI has optimized integration with `Nginx uWSGI`_ and100`Apache mod_proxy_uwsgi`_, and possibly other servers, instead of using101a standard HTTP proxy. That configuration is beyond the scope of this102doc, see the links for more information.103104.. _Nginx uWSGI: https://uwsgi-docs.readthedocs.io/en/latest/Nginx.html105.. _Apache mod_proxy_uwsgi: https://uwsgi-docs.readthedocs.io/en/latest/Apache.html#mod-proxy-uwsgi106107You can bind to all external IPs on a non-privileged port using the108``--http 0.0.0.0:8000`` option. Don't do this when using a reverse proxy109setup, otherwise it will be possible to bypass the proxy.110111.. code-block:: text112113 $ uwsgi --http 0.0.0.0:8000 --master -p 4 -w wsgi:app114115``0.0.0.0`` is not a valid address to navigate to, you'd use a specific116IP address in your browser.117118119Async with geventMerge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
lines 120–121why, one step back120-----------------121Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 122–126why, one step back122The default sync worker is appropriate for many use cases. If you need123asynchronous support, uWSGI provides a `gevent`_ worker. This is not the124same as Python's ``async/await``, or the ASGI server spec. You must125actually use gevent in your own code to see any benefit to using the126worker.Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 127why, one step back127Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 128–130why, one step back128When using gevent, greenlet>=1.0 is required, otherwise context locals129such as ``request`` will not work as expected. When using PyPy,130PyPy>=7.3.7 is required.Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 131why, one step back131Merge branch '2.1.x'David Lordbefore adoption9139af1
line 132why, one step back132.. code-block:: textMerge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 133why, one step back133Merge branch '2.1.x'David Lordbefore adoption9139af1
line 134why, one step back134 $ uwsgi --http 127.0.0.1:8000 --master --gevent 100 -w wsgi:appMerge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204
line 135why, one step back135Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 136–145why, one step back136 *** Starting uWSGI 2.0.20 (64bit) on [x] ***137 *** Operational MODE: async ***138 mounting hello:app on /139 spawned uWSGI master process (pid: x)140 spawned uWSGI worker 1 (pid: x, cores: 100)141 spawned uWSGI http 1 (pid: x)142 *** running gevent loop engine [addr:x] ***143144145.. _gevent: https://www.gevent.org/