Skip to content

Instantly share code, notes, and snippets.

Last active Oct 14, 2017
What would you like to do?
Running digitalocean/netbox under nginx + uwsgi

nginx + uwsgi installation

uwsgi is an alternative to using gunicorn + supervisord. It has native proxy support via the WSGI protocol in nginx.

# apt-get install uwsgi uwsgi-plugin-python3

Add a site to uwsgi in /etc/uwsgi/apps-available/netbox.ini:

chdir = /var/www/netbox/netbox
stats =
wsgi-file = netbox/
master = true
processes = 4
threads = 2
uid = www-data
socket = /run/uwsgi/netbox.sock
chown-socket = www-data:www-data
chmod-socket = 660
vacuum = true

Symlink it in /etc/uwsgi/apps-enabled:

# cd /etc/uwsgi/apps-enabled
# ln -s ../apps-available/netbox.ini .

For the nginx site setup in /etc/nginx/sites-available/netbox, a minimal example is:

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    ssl_certificate /etc/ssl/certs/netbox.crt;
    ssl_certificate_key /etc/ssl/private/netbox.key;
    server_name $hostname;
    keepalive_timeout 75;
    root /var/www/netbox;
    access_log /var/log/nginx/netbox.access combined;
    location /static/ {
        alias /var/www/netbox/netbox/static/;
    location / {
        uwsgi_pass unix:///run/uwsgi/netbox.sock;
        include uwsgi_params;

Finally, test configs & start the nginx and uwsgi services:

# uwsgi --show-config
# nginx -t
# service uwsgi start
# service nginx start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment