python3-django-uwsgi-nginx部署

在centos7 上部署django 项目
参考自https://blog.csdn.net/u014651560/article/details/125221725

环境准备
yum install python3
yum install python36-devel
python3 -m pip install  uwsgi
python3 -m pip install  django
python3 -m pip install  pymysql
pip3 install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com  cryptography==36.0.2  #连接mysql要用,版本不能变
拉取代码

.....

创建启动文件xxx_uwsgi.ini
文件位置:manager.py同级
内容:
[uwsgi] 
chdir = /root/yingtaicheng_power1
# 你的项目目录

module = yingtaicheng_power.wsgi:application  
# 指向自己Django项目目录下projectName目录下的wsgi文件 (上面的wsgi.py)

master = True 

processes = 4  
# 使用进程数  

threads = 2 
#使用的线程数

harakiri = 60  
# 最大超时时间

max-requests = 5000  
# 最大请求数,到了后就会自动重启

#socket = 127.0.0.1:8000  
# socket连接地址和端口,和nginx配置一致,
http = 0.0.0.0:18000 
# http方式,测试用这个方便
#http-socket = 0.0.0.0:8000    
#推荐使用http-socket

pidfile = /root/yingtaicheng_power1/master.pid
# 在失去权限前,将pid写到指定的pidfile文件中

daemonize = /root/uwsgi.log 
# 使进程在后台运行,并将日志打到指定的日志文件或者udp服务器, 不配置日志就是前台运行,部署测试时可以先注释掉
# chmod-socket    = 664  # 如果没有权限访问uWSGI的socket,这里可以设置权限

vacuum = True  
# 服务退出或重启,自动删除pid和socket文件

py-autoreload = 1  
#代码有修改重启

stats = :9191   
#配置查看服务运行状态的端口
创建wsgi.py
wsgi.py文件已存在不需要创建
启动
启动 
  uwsgi --ini  xx_uwsgi.ini 
停止 
  uwsgi --stop master.pid
重启
  uwsgi --reload master.pid
注意
启动时django日志可能会提示sqlite版本过低,如果没使用sqlite,可修改报错的那行代码,将判断的版本改低些

系统重启后了能需要手动删除master.pid再启动
使用nginx代理
nginx添加配置:
    server {
        listen 443 ssl;
        server_name  xx.com;
        location / {
              proxy_pass http://xx:8000/;
      }
    }

nginx重载配置
访问测试
posted @ 2022-07-28 18:17  tangshow  阅读(94)  评论(0编辑  收藏  举报