User-Profile-Image
hankin
  • 5
  • centos7
  • docker
  • mysql
  • PostgreSQL
  • git/gitlab
  • ELK
  • python
    • python-Tornado
    • python-django
  • redis
  • nginx
  • kvm
  • proxmox
  • mongo
  • kubernetes
  • prometheus
  • GlusterFs
  • nfs
  • freeswitch
  • httpd
  • shell脚本
  • linux
  • fastdfs
  • nextcloud
  • openssl
  • openvpn
  • rabbitmq
  • sqlite
  • svn
  • java
  • ubuntu
  • vue2
  • wordpress
  • php
  • IOT物联网
  • 项目
  • 故障处理
  • 树莓派
  • 博客存档
  • 未分类
  • 杂项
  • #1742(无标题)
  • 新视野
  • 分类
    • 项目
    • 树莓派
    • 杂项
    • 未分类
    • 新视野
    • 故障处理
    • 博客存档
    • 交换机
    • wordpress
    • vue2
    • ubuntu
    • svn
    • sqlite
    • shell脚本
    • redis
    • rabbitmq
    • python-django
    • python
    • proxmox
    • prometheus
    • PostgreSQL
    • php
    • openvpn
    • openssl
    • nginx
    • nfs
    • nextcloud
    • mysql
    • mongo
    • linux
    • kvm
    • kubernetes
    • java
    • IOT物联网
    • httpd
    • GlusterFs
    • git/gitlab
    • freeswitch
    • fastdfs
    • ELK
    • docker
    • centos7
  • 页面
    • #1742(无标题)
  • 友链
      请到[后台->主题设置->友情链接]中设置。
Help?

Please contact us on our email for need any support

Support
    首页   ›   python-django   ›   正文
python-django

python3-django-uwsgi-nginx部署

2022-10-28 23:33:38
814  0 0

在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重载配置
访问测试
评论 (0)

点击这里取消回复。

欢迎您 游客  

Copyright © 2025 网站备案号 : 蜀ICP备2022017747号
smarty_hankin 主题. Designed by hankin
主页
页面
  • #1742(无标题)
博主
tang.show
tang.show 管理员
linux、centos、docker 、k8s、mysql等技术相关的总结文档
213 文章 2 评论 202024 浏览
测试
测试