Django+Nginx+uwsgi 部署

  1. 云栖社区>
  2. 博客>
  3. 正文

Django+Nginx+uwsgi 部署

像教授 2017-11-26 20:14:00 浏览630
展开阅读全文

先决条件:

    nginx(>0.8);uwsgi;django;

    flup 下载地址:

    wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz

安装:

    sudo apt-get libxml2-dev python-dev

    flup和django   都是用 python setup.py install

    tar zxvf uwsgi-0.9.9.2.tar.gz
    cd uwsgi-0.9.9.2
    make -f Makefile.Py27 #和你安装PYTHON版本一致
    cp uwsgi /usr/sbin/uwsgi

配置:

    建立项目主目录:

    django-admin.py startproject  my_django

    在django主目录中建立django_wsgi.py

    import  os,sys
    import  django.core.handlers.wsgi
    os.environ['DJANGO_SETTINGS_MODULE']='my_django.settings'   #这里的my_django.settings 表示 "项目名.settings"
    application=django.core.handlers.wsgi.WSGIHandler()

    在主目录下 创建 uwsgi.xml文件:

    
  <uwsgi>  
  <socket>0.0.0.0:3001</socket>  
  <listen>20</listen>  
  <master>true</master>  
  <pidfile>/usr/local/nginx/uwsgi.pid</pidfile>  
  <processes>2</processes>  
  <module>django_wsgi</module>
  <pythonpath>/data/my_django</pythonpath>  #刚才建立项目的路径
  <profiler>true</profiler>  
  <memory-report>true</memory-report>  
  <enable-threads>true</enable-threads>  
  <logdate>true</logdate>  
  <limit-as>6048</limit-as>  
  </uwsgi>    

    添加nginx配置:

server {  
        listen  80;  
        server_name  django.sigh.com.cn;  
        location / {  
            root /data/my_django;
            uwsgi_pass   127.0.0.1:3001;  
            include     uwsgi_params;  
         }
}

 

启动uwsgi和nginx

/usr/local/nginx/sbin/nginx
uwsgi -x /data/my_django/uwsgi.xml &

 

uwsgi 控制脚本:可以存放在 /etc/init.d/uwsgi_con

#!/bin/bash  

LOG=/var/log/uwsgi  
CONF=/data/my_django/uwsgi.xml 
  
case "$1" in  
  start)  
    echo  "Starting uwsgi"  
    if [ -n "$PID" ]; then  
      echo "uwsgi is already running"  
      exit  
    else  
      uwsgi -x $CONF -d $LOG &> /dev/null  
    fi  
    ;;  
  stop)  
    echo  "Stopping uwsgi"  
    killall -QUIT uwsgi &> /dev/null   
    ;;  
  restart)  
    $0 stop  
    sleep 1  
    $0 start  
    ;;  
  *)  
    echo "usage: $0 {start|stop|restart}"    
esac  
exit 0 

验证过程:






本文转自 位鹏飞 51CTO博客,原文链接:http://blog.51cto.com/weipengfei/1135578,如需转载请自行联系原作者

网友评论

登录后评论
0/500
评论
像教授
+ 关注