Skip to content

Instantly share code, notes, and snippets.

@hellpanderrr
Last active March 25, 2016 07:00
Show Gist options
  • Select an option

  • Save hellpanderrr/3d6f47577f3e69820058 to your computer and use it in GitHub Desktop.

Select an option

Save hellpanderrr/3d6f47577f3e69820058 to your computer and use it in GitHub Desktop.
Ubuntu 14.04 Django1.9 Nginx Gunicorn Setup without virtualenv

sudo apt-get install nginx

sudo pip install gunicorn

/home/ubuntu/my_project -- path to the folder containing manage.py

/home/ubuntu/my_project/my_project -- path to the folder containing settings.py

$USER -- your username

sudo nano /etc/init/gunicorn.conf

description "Gunicorn application server handling myproject"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid $USER 
setgid www-data
chdir /home/ubuntu/my_project

exec gunicorn -c gunicorn.conf.py --workers 3 --bind unix:/home/ubuntu/my_project/my_project.sock my_project.wsgi:application

sudo nano /home/ubuntu/my_project/gunicorn.conf.py

errorlog = '/home/ubuntu/my_project/logs/gunicorn-error.log'
accesslog = '/home/ubuntu/my_project/logs/gunicorn-access.log'
loglevel = 'debug'

sudo nano /etc/nginx/sites-available/my_project

server {
    listen 80;
    server_name my.domain.net;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static {
        alias /home/ubuntu/my_project/static;
    }
    error_log /home/ubuntu/my_project/logs/error.log info;
    access_log /home/ubuntu/my_project/logs/access.log;
    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/my_project/my_project.sock;
    }
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment