gunicore+nginx项目部署(Django,阿里云服务器)

  1. 在你的服务安装(pip install gunicorn gevent)
  2. 在你主目录建立一个gunicorn-config.py文件,文件名可以随便起
    在这里插入图片描述
  3. 编写gunicorn-config.py,新建logs文件夹
    注意:下面代码bind = [“127.0.0.1:9999”]在nginx反向代理的时候会用到,必须一致,为什么建立logs文件夹?用来存日志,细心的同学会发现,pidfile ,errorlog 中用到,他不像uwsgi会自动创建,需要手动创建
    在这里插入图片描述
from multiprocessing import cpu_count

bind = ["127.0.0.1:9999"]  # 线上环境不会开启在公网 IP 下,一般使用内网 IP
daemon = True  # 是否开启守护进程模式
pidfile = 'logs/gunicorn.pid'

workers = cpu_count() * 2  # 工作进程数量
worker_class = "gevent"  # 指定一个异步处理的库
worker_connections = 65535

keepalive = 60  # 服务器保持连接的时间,能够避免频繁的三次握手过程
timeout = 30
graceful_timeout = 10
forwarded_allow_ips = '*'

# 日志处理
capture_output = True
loglevel = 'info'
errorlog = 'logs/gunicorn-error.log'

4.启动gunicore

gunicorn -c ./swiper/gunicorn-config.py swiper.wsgi

在这里插入图片描述6.配置nginx(这个在我部署的分类中说得太多次了,我就不写了)
在/etc/nginx/conf.d下建立一个自己命名的.conf文件,编写,直接复制粘贴就好,需要自己改为直接的路径
在这里插入图片描述

server {
        listen 8888;
        server_name localhost;
        location /static/ {
                alias /root/kola/static/;
                }
        location / {
                proxy_pass http://127.0.0.1:9999;
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                }

}

7.重启nginx(nginx -s reload)
8.在浏览器输入(服务器ip:8888/你的url)例如24.389.44.20:8888/index/…
当然这个是假的,只是让你们知道如何访问自己的项目

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章