Skip to content

uwsgi

install

system wide

# apt install uswgi-emperor
# apt install uwsgi-plugin-python3

uwsgi-emperor is installed at OS level, then each application will spawn its own interpreter, within a virtualenv if instructed.

Info

If a different interpreter version than distribution is to be used in virtualenv, do not install uwsgi-plugin-python3.deb.
/usr/bin/uwsgi-core and plugin should be compiled manually (see below).

uwsgi & plugin compilation

If uwsgi is intended to run within virtualenv with a given python version, plugin needs to be compiled.

Warning

Initialize a virtualenv with desired PythonX.Y, compiled with -fPIC flags [python]
Plugin MUST be compiled with same interpreter as plugin target

(env) $ wget https://projects.unbit.it/downloads/uwsgi-lts.tar.gz
(env) $ tar xvfz uwsgi-lts.tar.gz
(env) $ cd uwsgi-x.y.z
(env) $ python3 uwsgiconfig.py --build
// python3<MAJOR> means python39 or python311 (without space) for python3.9 or 3.11 resp.
(env) $ python3 uwsgiconfig.py --plugin plugins/python core python3<MAJOR>
Compiled uwsgi should be copied as /usr/bin/uwsgi-core
Compiled plugin should be copied as /usr/lib/uwsgi/plugins/python3<MAJOR>_plugin.so

Warning

releases list
uwsgi supports python 3.12 after version 2.0.23
uwsgi supports python 3.11 after version 2.0.21

config

emperor

/etc/uwsgi-emperor/emperor.ini
[uwsgi]
emperor = /etc/uwsgi-emperor/vassals
uid = nginx
gid = nginx
log-date = true
logto = /var/log/uwsgi/emperor.ini

vassals

/etc/uwsgi-emperor/vassals/[PROJECT].ini
[uwsgi]
master = true
workers = 4                                 # good number is n-CPUs
no-orphans = true
lazy-apps = true                            # no shared mem between workers, crucial for db cnx
env = APP_HOST=<HOST>
env = APP_ENV=dev
env = APP_API_VERSION=1
virtualenv = /var/srvr/<PROJECT>/dev
chdir = /var/srvr/<PROJECT>/dev
socket = /var/uwsgi/<PROJECT>/dev.socket
plugins-dir = /usr/lib/uwsgi/plugins        # otherwise emperor.ini logs unable to find shared plugin
plugins = python311
wsgi-file = main.py
callable = application
logto = /var/log/uwsgi/<PROJECT>_dev.log
stats = /tmp/stats_%n
py-autoreload = 3                           # [!] remove in production

monitoring

stats = 127.0.0.1:9000 in emperor.ini
stats = 127.0.0.1:900n for each vassal
uwsgi-prometheus plugin give little added value.