Django与web服务器(Ningx和uWSGI)的部署与配置 - pingdongyi/blog-2 GitHub Wiki
这里简单介绍django框架与nginx和uwsgi的部署与配置,可参考官方文档
要用django框架当然得有安装python了,安装python如下所示:
apt-get install python
或是
brew install python
可以参考官网文档
-
wget https://bootstrap.pypa.io/get-pip.py
-
安装pip
python get-pip.py
-
直接用pip安装
pip install Django
-
根据最新的源代码安装
git clone git://github.com/django/django.git pip install -e django/
-
创建项目
django-admin.py startproject demo cd demo
-
执行下面命令安装uwsgi:
pip install uwsgi
-
以文件形式配置uwsgi
创建配置文件demo_uwsgi.ini,如下所示:
# mysite_uwsgi.ini file [uwsgi] # Django-related settings # the base directory (full path) chdir = /Users/zhangbingbing/Public/www/demo # Django's wsgi file module = demo.wsgi # the virtualenv (full path) #home = /path/to/virtualenv # process-related settings # master master = true # maximum number of worker processes processes = 10 # the socket (use the full path to be safe socket = /Users/zhangbingbing/Public/www/demo/demo.sock # ... with appropriate permissions - may be needed # chmod-socket = 664 # clear environment on exit vacuum = true
-
启动uwsgi
-
直接命令行启动
uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=664
-
以配置文件启动
uwsgi --ini demo_uwsgi.ini
-
-
配置nginx,以使用请求发到uwsgi
##8008端口for django frame server { listen 8003; server_name localhost; charset utf-8; client_max_body_size 75M; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location /static { root /Users/zhangbingbing/Public/www/demo; } location / { root /Users/zhangbingbing/Public/www/demo; uwsgi_pass django; #uwsgi_pass unix:///Users/zhangbingbing/Public/www/demo/demo.sock; include uwsgi_params; #uwsgi_read_timeout 180; } location ~ /\.ht { deny all; } } upstream django{ #server 127.0.0.1:9999; server unix:///Users/zhangbingbing/Public/www/demo/demo.sock; }
-
启动nginx
nginx -s stop nginx -c /usr/local/etc/nginx/nginx.conf nginx -s reload