Skip to content

Instantly share code, notes, and snippets.

@avsilva
Last active March 24, 2016 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avsilva/5b26506d38b95af8eeba to your computer and use it in GitHub Desktop.
Save avsilva/5b26506d38b95af8eeba to your computer and use it in GitHub Desktop.
nginx + uwsgi + django in Ubuntu 14.04

Install and configure nginx + uwsgi + django

  • sudo apt-get update
  • sudo apt-get install nginx
  • sudo pip install uwsgi
  • sudo mkdir /etc/uwsgi
  • sudo mkdir /etc/uwsgi/vassals
  • edit /etc/nginx/sites-available/default
upstream django {
    server unix:///tmp/ifas.sock; # for a file socket
}

# configuration of the server
server {
    listen      80;

    server_name _
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    location /static {
        alias /project-dir/module-name/static/;
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        proxy_read_timeout 300;
        uwsgi_pass  django;
        include     uwsgi_params;
    }
}
  • edit /etc/uwsgi/vassals/project-name.ini
    [uwsgi]
    # Django-related settings
    # the base directory (full path)
    chdir = /projectdir #modify according to your project base dir 
    # Django's wsgi file
    module = app.wsgi #modify according to your app name 
    # process-related settings
    # master
    master          = true
    # maximum number of worker processes
    processes       = 10
    # the socket (use the full path to be safe
    socket          = /tmp/ifas.sock
    # ... with appropriate permissions - may be needed
    chmod-socket    = 666
    # clear environment on exit
    vacuum = true
  • sudo nginx
  • uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment