声明:
1、本篇文章是我边写命令边写的,请尊重我的劳动成果,转载请加上链接。
2、我既然公开写出来,是希望大家遇到问题的时候有个参考,所以,大家可以免费转载,使用该文章
3、但是,如果你要用这篇文章来赚钱,sorry,你至少得分我点吧。
使用gunicorn 来部署django
django写代码简单,但部署是个难题,今天终于发现gunicorn 这个好东西,与大家一起分享。
环境:ubuntu 14.04 64bit + django 1.6.5 + virtualenv + gunicorn
一、创建虚拟环境
root@recall:/home/www# pwd /home/www root@recall:/home/www# virtualenv bugenv New python executable in bugenv/bin/python Installing setuptools, pip...done. root@recall:/home/www# ll total 16 drwxr-xr-x 4 root root 4096 Jul 21 15:04 ./ drwxr-xr-x 5 root root 4096 Jul 21 12:34 ../ drwxr-xr-x 6 root root 4096 Jul 21 15:05 bugenv/ ....................................(这一行是私人数据,这里不影响,所以不显示了)
二、进入虚拟环境
root@recall:/home/www# cd bugenv/ root@recall:/home/www/bugenv# source bin/activate (bugenv)root@recall:/home/www/bugenv#
三、下载django和gunicorn
pip install django==1.6.5
pip install gunicorn
1 (bugenv)root@recall:/home/www/bugenv# pip install django==1.6.5 2 Downloading/unpacking django==1.6.5 3 Downloading Django-1.6.5-py2.py3-none-any.whl (6.7MB): 6.7MB downloaded 4 Installing collected packages: django 5 Successfully installed django 6 Cleaning up... 7 (bugenv)root@recall:/home/www/bugenv# pip install gunicorn 8 Downloading/unpacking gunicorn 9 Downloading gunicorn-19.0.0.tar.gz (382kB): 382kB downloaded 10 Running setup.py (path:/home/www/bugenv/build/gunicorn/setup.py) egg_info for package gunicorn 11 12 warning: no previously-included files matching '*.pyc' found under directory 'docs' 13 warning: no previously-included files matching '*.pyo' found under directory 'docs' 14 warning: no previously-included files matching '*.pyc' found under directory 'tests' 15 warning: no previously-included files matching '*.pyo' found under directory 'tests' 16 warning: no previously-included files matching '*.pyc' found under directory 'examples' 17 warning: no previously-included files matching '*.pyo' found under directory 'examples' 18 Installing collected packages: gunicorn 19 Running setup.py install for gunicorn 20 21 warning: no previously-included files matching '*.pyc' found under directory 'docs' 22 warning: no previously-included files matching '*.pyo' found under directory 'docs' 23 warning: no previously-included files matching '*.pyc' found under directory 'tests' 24 warning: no previously-included files matching '*.pyo' found under directory 'tests' 25 warning: no previously-included files matching '*.pyc' found under directory 'examples' 26 warning: no previously-included files matching '*.pyo' found under directory 'examples' 27 File "/home/www/bugenv/lib/python2.7/site-packages/gunicorn/workers/gaiohttp.py", line 67 28 yield from self.wsgi.close() 29 ^ 30 SyntaxError: invalid syntax 31 32 Installing gunicorn_paster script to /home/www/bugenv/bin 33 Installing gunicorn script to /home/www/bugenv/bin 34 Installing gunicorn_django script to /home/www/bugenv/bin 35 Successfully installed gunicorn 36 Cleaning up... 37 (bugenv)root@recall:/home/www/bugenv#