Web Application Setup - uWSGI Set Up
Set Up uWSGI To Server Your Application
-
Create your uWSGI configuration file:
... touch /var/www/appname/config/uwsgi-appname.ini -
Contents of your
uwsgi-appname.inishould look like this:[uwsgi] plugins = python3,logfile chdir = /var/www/appname home = /var/www/appname/venv wsgi-file = /var/www/appname/wsgi.py master = True cheap = True idle = 600 die-on-idle = True manage-script-name = True -
Link your config file so uwsgi can find it:
... cd /etc/uwsgi/apps-enabled ... ln -s /var/www/appname/config/uwsgi-appname.ini appname.ini
SYSTEMD UWSGI SET UP
-
Create systemd socket and server files for your uwsgi app:
... touch uwsgi@appname.socket ... touch uwsgi@appname.serviceThe content of these files are generic - for additional apps these could be copied or linked with the new app name (e.g.
uwsgi@appname2.socket).Systemdwill will interpolate the conent between the@and.in the file/link name with the%idirective in the files. -
Your
uwsgi@appname.socketfile:[Unit] Description=Socket for uWSGI app %i [Socket] ListenStream=/var/run/uwsgi/%i.socket SocketUser=www-%i SocketGroup=www-data SocketMode=0660 [Install] WantedBy=sockets.target -
Your
uwsgi@appname.servicefile:[Unit] Description=%i uWSGI app After=syslog.target [Service] ExecStart=/usr/bin/uwsgi \ --ini /etc/uwsgi/apps-enabled/uwsgi-%i.ini \ --socket /var/run/uwsgi/%i.socket User=www-%i Group=www-data Restart=on-failure KillSignal=SIGQUIT Type=notify StandardError=syslog NotifyAccess=all -
Link these files to the
systemdconfig directory:... cd /etc/systemd/system ... ln -s /var/www/appname/config/uwsgi@appname.socket ./ ... ln -s /var/www/appname/config/uwsgi@appname.service ./ -
Start up uWSGI:
... sudo systemctl enable uwsgi@appname.socket ... sudo systemctl enable uwsgi@appname.service ... sudo systemctl start uwsgi@appname.socket