Skip to content

Instantly share code, notes, and snippets.

@mtkp
Created September 3, 2014 21:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtkp/fd94d39aa33ecc0e2dda to your computer and use it in GitHub Desktop.
Save mtkp/fd94d39aa33ecc0e2dda to your computer and use it in GitHub Desktop.
Simple configuration: Django + Nginx + Gunicorn
# /etc/gunicorn.d/gunicorn-proj
CONFIG = {
'mode': 'django',
'user': 'myuser',
'group': 'myuser',
'working_dir': '/path/to/django/proj',
'environment': {
'PYTHONPATH': '/path/to/django/proj'
},
'args': (
'--bind=127.0.0.1:8040',
'--workers=3',
'conf.settings',
),
}
# /etc/nginx/sites-available/nginx-proj
upstream app_server {
server 127.0.0.1:8040;
}
server {
listen my.ip.or.dns:80;
location /static/ {
alias /path/to/static/;
}
location / {
proxy_pass http://127.0.0.1:8040;
proxy_pass_request_headers on;
}
}
# /path/to/django/proj/conf/settings.py
# Django project settings file (moved into a separate directory, `conf`)
# ...
ALLOWED_HOSTS = ['127.0.0.1']
STATIC_ROOT = '/path/to/static/'
# ...
@mtkp
Copy link
Author

mtkp commented Sep 3, 2014

Simple configuration to get started with Nginx, Gunicorn, and Django.

After installing Nginx and Gunicorn (through apt-get), and setting up the above configurations, you can start the web server with:

$ service nginx start
$ service gunicorn start

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