Skip to content

Instantly share code, notes, and snippets.

@TimSC
Last active January 4, 2017 22:24
Show Gist options
  • Select an option

  • Save TimSC/0193fa92d7fe5b63769eeca5c42fd5d5 to your computer and use it in GitHub Desktop.

Select an option

Save TimSC/0193fa92d7fe5b63769eeca5c42fd5d5 to your computer and use it in GitHub Desktop.
Recipe for getting nginx-uwsgi-django working on Mint 18.1 (which is systemd based)
  • cd /var/www
  • sudo django-admin startproject mysite
  • sudo chown www-data:www-data -R mysite
  • sudo chmod g+rw -R mysite
  • cd mysite
  • sudo pip install uwsgi
  • python manage.py startapp polls

sudo xed /etc/nginx/sites-available/mysite

# the upstream component nginx needs to connect to
upstream django {
    server unix:///run/mysite.sock; # for a file socket
    # server 127.0.0.1:8001; # for a web port socket
}

# Default server configuration
#
server {
    listen 81;
    listen [::]:81;

    root /var/www/mysite;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
        uwsgi_pass  django;
    }

}

sudo ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/mysite

sudo service nginx restart

/var/www/mysite/mysite.ini

# mysite_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /var/www/mysite
# Django's wsgi file
wsgi-file          = mysite/wsgi.py
# the virtualenv (full path)
#home            = /path/to/virtualenv

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 2
# the socket (use the full path to be safe
socket          = /run/mysite.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 664
# clear environment on exit
vacuum          = true

python-autoreload = 1

sudo xed /etc/systemd/system/mysite.service

[Unit]
Description=uWSGI instance to serve mysite
After=network.target

[Service]
User=root
Group=www-data
WorkingDirectory=/var/www/mysite
ExecStart=/usr/local/bin/uwsgi --ini mysite.ini
KillSignal=SIGQUIT

[Install]
WantedBy=multi-user.target
  • sudo systemctl start mysite.service
  • sudo systemctl enable mysite.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment