Install uwsgi:

apt-get install build-essential python
sudo pip3 install uwsgi

Create a service in /etc/systemd/system/uwsgi.service

[Unit]
Description=uWSGI Emperor service

[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown www-data:www-data /run/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target

Create an emperor file at:

sudo mkdir /etc/uwsgi
sudo mkdir /etc/uwsgi/sites
sudo vi /etc/uswsgi/sites/stocks.ini

And then add:

[uwsgi]
project = stocks
uid = bpopp
base = /usr/share/nginx/html/django

chdir = %(base)/%(project)
module=%(project).wsgi:application

master = true
processes = 5
threads=2

http = 0.0.0.0:8001

Now start uwsgi

sudo service uwsgi start

Check that the service and your application are running at:

http://www.lab.bpopp.net:8001

Set service to start automatically

sudo systemctl enable uwsgi.service


Configure NGINX (optional)

At the top (outside the server declaration) of /etc/nginx/conf.d/default.conf:


upstream uwsgicluster {
        server 127.0.0.1:8001;
    }

At the bottom (inside the server declaration) add the proxy:

 location /django/stocks {
        include uwsgi_params;
        uwsgi_pass  uwsgicluster;

        proxy_redirect     off;
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $server_name;
    }