uwsgi+django 配置

uwsgi+django

  1. 创建新的虚拟环境,且解决crm的环境依赖

  2. 在虚拟环境下安装uwsgi

    pip3 install uwsgi 
    
  3. 学习uwsgi命令,如何启动python应用 启动python web文件 创建一个test.py写入如下代码

    1def application(env, start_response): 2 start_response('200 OK', [('Content-Type','text/html')]) 3 return [b"Hello World"] # python3

    用uwsgi启动一个python web文件

    指定8000端口启动 http服务

    指定wsgi文件

    uwsgi --http :8000   --wsgi-file  test.py 
    
  4. 用uwsgi启动django项目 uwsgi --http :9000 --module Alibab_crm.wsgi

    uwsgi加上热加载命令 uwsgi --http :8000 --module Alibab_crm.wsgi --py-autoreload=1

    使用uwsgi配置文件去启动项目

    1. 手动创建uwsgi.ini 配置文件 (alicrm) [root@s16ds Alibab_crm]# cat uwsgi.ini

      1# mysite_uwsgi.ini file 2[uwsgi] 3# Django-related settings 4# the base directory (full path) 5#指定django的项目目录,第一层 6chdir = /opt/Alibab_crm 7# Django's wsgi file 8#找到django的wsgi文件 9#这里需要写项目的第二层目录Alibab_crm 10module = Alibab_crm.wsgi 11# the virtualenv (full path) 12#填写虚拟环境的绝对路径 13home = /root/Envs/alicrm 14# process-related settings 15# master 16master = true 17# maximum number of worker processes 18processes = 5 19# the socket (use the full path to be safe 20#指定socket协议,运行django,只能与nginx结合时使用 21#指定socket协议,运行django,只能与nginx结合时使用 22#指定socket协议,运行django,只能与nginx结合时使用 23socket = 0.0.0.0:8000 24#如果你没用nginx,只想自己启动一个http界面,用这个 25#http = 0.0.0.0:8000 26 27# ... with appropriate permissions - may be needed 28# chmod-socket = 664 29# clear environment on exit 30vacuum = true
    2. 通过配置文件启动uwsgi

      uwsgi --ini uwsgi.ini  
      
  5. 收集django crm的静态文件

    编辑crm的settings.py配置文件 写入如下代码

    1# 定义django的静态资源根目录,便于用命令收集资源,存放的地儿 2STATIC_ROOT="/opt/crm_static" 3STATIC_URL = '/static/' 4STATICFILES_DIRS = [ 5 os.path.join(BASE_DIR, 'static') 6 7] 8

    用命令收集静态文件

    python3 manage.py collectstatic 
    
  6. 配置nginx,反响代理django服务器,且解析静态文件

    proxy_pass 仅仅是请求转发的参数,与uwsgi结合,还有跟高级的协议参数

    修改nginx配置文件如下

    1server { 2 listen 80; 3 server_name s16chiji.com; 4 location / { 5 #root /opt/s16chiji; 6 #index index.html; 7 #使用uwsgi_pass 转发基于uwsgi协议的一个请求 8 9 uwsgi_pass 192.168.15.71:8000; 10 include /opt/nginx112/conf/uwsgi_params; 11 } 12 #配置一个url的入口,告诉django静态文件在哪里去找 13 #当请求url是 s16chiji.com/static/的时候 14 #就进行别名,nginx去/opt/crm_static下寻找js文件 15 location /static { 16 alias /opt/crm_static/; 17 } 18 #通过这个参数,定义错误页面的文件 ,当状态码是 404 400 401 时,返回40x.html页面 19 error_page 404 401 400 403 /40x.html; 20 }
  7. 此时nginx结合uwsgi 已经完成

  8. 记住这里推出虚拟环境,使用物理环境去运行

配置supervisor工具,管理django后台

  • 这个东西只能用python2去实现
  1. 下载supervisor

    easy_install supervisor 
    
  2. 配置supervisor的配置文件,编写django任务

    echo_supervisord_conf >  /etc/supervisor.conf 
    
  3. 编写运行django的任务

    vim /etc/supervisor.conf 在最底行写入如下代码

    1[program:s16alicrm] 2command=/root/Envs/alicrm/bin/uwsgi --ini /opt/Alibab_crm/uwsgi.ini 3autorestart=true 4stopasgroup=true 5killasgroup=true
  4. 启动suopersivod这个程序

    1启动服务端 2supervisord -c /etc/supervisor.conf 3通过客户端命令查看任务 4supervisorctl -c /etc/supervisor.conf
  5. 学习supervisor管理命令

    1[root@s16ds alicrm]# supervisorctl -c /etc/supervisor.conf 2s16alicrm RUNNING pid 5293, uptime 0:03:03 3supervisor> stop all #停止所有任务 4supervisor> start all #启动s所有任务 5supervisor> status s16alicrm
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

KVM调整cpu和内存

一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid