Tested in Ubuntu 14.04 LTS
, django 1.9
, gunicorn 17.5
, supervisord 3.0b2
, nginx 1.4.6
Reference: django gunicorn supervisord nginx
Demo django project /tmp/myproject
django
run django in debug mode
cd /tmp/myproject python manage.py runserver 0.0.0.0:9999
|
static files
vim /tmp/myproject/myproject/settings
add STATIC_ROOT= os.path.join(BASE_DIR,'static')
python manage.py collectstatic
|
Generate a directory named static
in /tmp/myproject/myproject
nginx
vim /etc/nginx/sites-available/myproject.conf
server { listen 80; server_name yourip; root /tmp/myproject; access_log /var/log/nginx/myproject.log; location /static { alias /tmp/myproject/myproject/static; } location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_connect_timeout 6000; proxy_read_timeout 6000; proxy_pass http://127.0.0.1:9999/; } }
|
cd /etc/nginx/sites-enabled ln -s /etc/nginx/sites-available/myproject.conf ./ service nginx reload
|
gunicorn
gunicorn myproject.wsgi -b 0.0.0.0:9999
|
Must excuted in /tmp/myproject
supervisor
cat /etc/supervisor/conf.d/myproject.conf
[program:myproject] command=gunicorn myproject.wsgi -b 0.0.0.0:9999 directory=/tmp/myproject autostart=true autorestart=true
|
supervisorctl reread service supervisor restart supervisorctl status myproject
|