Skip to content
Myr

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 file

Take 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 back
1uWSGI
2=====3

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 4–5why, one step back
4`uWSGI`_ is a fast, compiled server suite with extensive configuration
5and capabilities beyond a basic server.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 6why, one step back
6

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 7–11why, one step back
7* 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 back
12

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 13–14why, one step back
13This page outlines the basics of running uWSGI. Be sure to read its
14documentation to understand what features are available.

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 15why, one step back
15

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 16why, one step back
16.. _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 back
17
18

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 19–20why, one step back
19Installing
20----------

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 21why, one step back
21

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 22–25why, one step back
22uWSGI has multiple ways to install it. The most straightforward is to
23install 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 back
26

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 27why, one step back
27Create 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 back
28

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 29why, one step back
29.. code-block:: text

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 30why, one step back
30

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 31why, one step back
31 $ cd hello-app

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

lines 32–33why, one step back
32 $ python -m venv .venv
33 $ . .venv/bin/activate

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 34–35why, one step back
34 $ pip install . # install your application
35 $ pip install pyuwsgi

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 36why, one step back
36

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 37–39why, one step back
37If you have a compiler available, you can install the ``uwsgi`` package
38instead. 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 back
40

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 41–119why, one step back
41.. code-block:: text
4243 $ 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 gevent

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

lines 120–121why, one step back
120-----------------
121

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 122–126why, one step back
122The default sync worker is appropriate for many use cases. If you need
123asynchronous 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 back
127

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 128–130why, one step back
128When using gevent, greenlet>=1.0 is required, otherwise context locals
129such 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 back
131

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 132why, one step back
132.. code-block:: text

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 133why, one step back
133

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 134why, one step back
134 $ uwsgi --http 127.0.0.1:8000 --master --gevent 100 -w wsgi:app

Merge pull request #4189 from mgu/feat/use-exclude-patterns-reloaderDavid Lordbefore adoption48ee204

line 135why, one step back
135

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 136–145why, one step back
136 *** 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/