gunicorn+anaconda+nginx部署django项目(ubuntu)

首先进入conda 虚拟环境:

  source activate test

安装gunicorn:

  pip install gunicorn

  运行gunicorn 

    gunicorn -w 2 -b 127.0.0.1:9200 -D test.wsgi:application   # -D 为后台运行

    或者配置gunicorn.py  文件,并放置在项目根目录下:

from gevent import monkey
monkey.patch_all()
import multiprocessing
debug = True
loglevel = 'debug'
bind = '127.0.0.1:9200' //绑定与Nginx通信的端口
pidfile = 'log/gunicorn.pid'
logfile = 'log/debug.log'
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'gevent' //默认为阻塞模式,最好选择gevent模式

    并运行 gunicorn -c gunicorn.py test.wsgi:application -D

    这时可以用ps -ef | grep gunicorn 命令看gunicorn是否运行

接下来配置nginx:

  在配置nginx前,先要在django setting 文件中host中加上localhost,否则会报400错误。并重启gunicorn, kill -HUP pid (ps -ef | grep gunicorn 查看pid)

  首先安装nginx, 运行命令      sudo apt install nginx

  nginx 命令:

    sudo service nginx start    启动

    sudo service nginx stop   停止

    sudo service nginx restart  关闭

  配置文件:

    sudo vim /etc/nginx/site-available/test.conf

server {
        listen 8000;
        charset utf-8;
        client_max_body_size 75M;
        location / {
                proxy_pass http://127.0.0.1:9200;
        }
}

  并生成软链接   sudo ln -s /etc/nginx/site-available/test.conf /etc/nginx/site-enabled/test.conf

  重启nginx, sudo service nginx restart

转载于:https://www.cnblogs.com/jiaxiaoxin/p/10646101.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值