Django 1.9 部署

1. uwsgi部署

step 1: 配置文件 uwsgi.ini

[uwsgi]

chdir=/path/to/project

module=projectname.wsgi:application

master=True

pidfile=/path/lic.pid

vacuum=True

max-requests=5000

daemonize=/path/projectname.log

static-map=/static=/os/path/to/collected_static

processes=4

http=0.0.0.0:8000

step 2: 启动  uwsgi --ini uwsgi.ini

step 3: 停止 killall -9 uwsgi


2. Nginx 部署

step 1: 安装 Nginx (mac osx)

brew install nginx

step 2: uwsgi.ini

[uwsgi]
chdir=/path/to/project/
module=projectname.wsgi:application
master=True
pidfile=/path/to/projectname.pid
vacuum=True
max-requests=5000
daemonize=/path/to/projectname.log
#static-map=/static=/path/to/collected_static/
processes=2
#用 http 连接⬇︎
#http=0.0.0.0:8080       
#用 socket连接⬇︎
socket = /tmp/projectname.sock
#socket 文件权限⬇︎
#chmod-socket=664 
#socket 文件用户/组⬇︎
#chown-socket=user:group 

step 3: 配置 nginx.conf
server {
    listen   8000;
    server_name localhost;
    location / {
        include uwsgi_params;
        #proxy_pass   http://127.0.0.1:8080;  #用 http 连接
        uwsgi_pass  unix:///tmp/projectname.sock;        #用 socket 连接
        #uwsgi_read_timeout 1800;
    }
    location /static {
        alias  /path/to/collected_static/;
    }
}

step 4: 启动 uwsgi --ini uwsgi.ini
step 5: 启动 nginx
step 6: 访问 localhost:8000

说明:注意 uwsgi.ini 与 nginx.conf 中使用 http 还是 socket 连接要一致;当 uwsgi与 nginx 在同一台机器上时建议使用 socket 方式。


3. 使用 supervisor 管理 uwsgi 进程


supervisor就是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启。

step 1: 安装 supervisor
    pip install supervisor
step 2: 生成 supervisor 默认配置文件
    echo_supervisord_conf > /path/to/supervisord.conf
    说明:supervisord.conf应位于/usr/local/etc/, /usr/local/,/etc/或/etc/supervisor/
step 3: 配置 supervisor.conf,在其底部添加
    [program:projectname]
    command=/path/to/uwsgi --ini /path/to/uwsgi.ini
    directory=/path/to/project
    stopasgroup=true
    stopsignal=KILL
    killasgroup=true
    ;process_name = lic_%(process_num)s
    numprocs = 1
    startsecs = 0
    autostart = true
    autorestart=false
    startretries=0
step 4: 运行 supervisord
step 5: 重启 supervisor
    supervisorctl restart projectname
    或者
    supervisorctl restart all

说明:supervisorctl 也是一个交互式环境,常用命令有 status、start、stop、restart、shutdown 等;不过可惜的是在osx系统中暂时还没有搞定上述内容3,利用 supervisor 启动 uwsgi 没问题,但是它无法观测到 uwsgi 的状态,因此无法停止,再次启动会重复创建进程。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值