Python+Django+nginx+Linux+gunicorn部署
初次部署Django project in ubuntu server
Init env:
python -V 2.7.3
Django 1.6
Linux ubuntu
Steps:
- install nginx
- install gunicorn sudo apt-get install gunicorn
- create django project django-admin.py startproject demos
- test gunicorn is useful cd demos && gunicorn demos.wsgi:application --bind 0.0.0.0:9090
- config nginx for demos
upstream demos { server 127.0.0.1:9090 fail_timeout=0; #server unix:/var/www/demos/run/gunicorn.sock } server { listen 8000; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; root /var/www/demos; server xxxx.com; location / { proxy_pass http://demos; } location /static { ..... } error_page 404 500 504 /404.html; location = /404.html { root html; } }
测试页面 http://127.0.0.0:8000 ,see "Congratulations on your first Django-powered page." successfully
- run gunicorn process backend, using supervisor
- sudo apt-get install supervisor
- config supervisor
- config shell script for gunicorn
#!/bin/bash name="demos" project_dir=/var/www/demos sockfile=/var/www/demos/run/gunicorn.sock address=0.0.0.0 port=9090 num_wks=3 dj_setting_module=demos.settings dj_wsgi_module=demos.wsgi echo "Starting $name as `whoami`" rundir=$(dirname $sockfile) test -d $rundir || mkdir -p $rundir exec gunicorn ${dj_wsgi_module}:application \ --workers $num_wks \ --log-level=debug \ --bind=$address:$port #--bind=unix:$sockfile
- update supervisor.conf
[program:demos] command = /var/www/demos/run/runserver.sh stdout_logfile = /var/www/demos/logs/gunicorn_supervisor.log redirect_stderr = true
- start supervisorctl demos
Refs:
http://ijcdigital.com/blog/django-gunicorn-and-nginx-setup
http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
相关推荐
htofly 2020-06-03
username=user ; should be same as http_username if set. password=123 ; should be same as http_passwo
bysidewithsun 2020-05-14
lap00 2020-05-05
SDUTACM 2020-05-03
wangyibo00 2020-03-07
柠檬班 2020-02-03
wangyibo00 2019-10-06
dashoumeixi 2019-09-11
xufwind 2012-06-27
tuxlcsdn 2019-07-01
lnkToKing 2019-06-30
七夕小子 2019-06-29
bigzhao 2019-06-28
mingrixing 2019-06-28
kewei 2019-06-27
Owengoodman 2019-06-26
wangyibo00 2019-06-26
Owengoodman 2014-01-19