11.CentOS7部署Django(前后端不分离)

前提

已经安装好uwsgi,supervisor,Tenginx

步骤1.uwsgi.ini配置($Home//document/CRM/crm/crm/uwsgi.ini)

[uwsgi]
# Django-related settings
# the base directory (full path)
chdir           = /home/jason/document/CRM/crm/
# Django's wsgi file
module          = crm.wsgi
# the virtualenv (full path)
home            = /root/.virtualenvs/MyCRM

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 2
buffer-size = 65536
# the socket (use the full path to be safe
#http         = 0.0.0.0:8080
#the socket (use the full path to be safe)
#这里的socket参数,用户和nginx结合部署的unix-socket参数,使用此协议运行后台,就无法通过浏览器访问
socket        = 0.0.0.0:8080
# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum          = true
#daemonize = /home/jason/document/CRM/crm/crm/debug.log

步骤2.supervisod.conf(/etc/supervisod.conf)

[program:crm]
;uwsgi启动命令
command=/root/.virtualenvs/MyCRM/bin/uwsgi --ini /home/jason/document/CRM/crm/crm/uwsgi.ini
;是否随supervisor的启动而启动
autostart=true
;启动10秒后没有异常则进程正常启动,默认为1s
startsecs=10
;程序退出后自动重启,可选值[unexpected,true,false] 默认为unexpected,表示进程意外kill掉后才重启
autorestart=true
;默认为false,进程被杀死时,是否向这个进程发送stop信号,包括子进程
stopasgroup=true
;默认为false,进程被杀死时,是否向这个进程发送kill信号,包括子进程
killasgroup=true

步骤3.ningx.conf (/opt/nginx233/conf)

#user  nobody;
#定义了nginx的工作进程数,以Cpu核数为准
worker_processes  auto;

#Nginx错误日志存放路径
error_log  logs/error.log;


#Nginx服务运行后产生的pid进程号
pid        logs/nginx.pid;


events {
  #每个worker进程支持的最大连接数
  worker_connections  1024;
}


http {
  #包含/etc/nginx/conf.d/目录下所有以.conf结尾的文件
  include mime.types;
  default_type  application/octet-stream;
  # 打开此nginx的访问日志功能,即可查看日志
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  '$status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"';

  sendfile        on;
  keepalive_timeout  65;
  # nginx开启静态资源压缩,比如nginx返回磁盘的html文件特别大,里面包含了诸多的静态文件,极大提升网站访问
  gzip  on;
  #提供静态资源缓存功能,第一次访问过网页后,nginx能让静态资源缓存到浏览器上
  #虚拟主机代码块
  server {
    #网站端口
    listen       80;
    #网站域名
    server_name  localhost;
    #网站编码
    charset utf-8;
    access_log  logs/host.access.log  main;
    #域名匹配模块
    location / {
      #proxy_pass http://192.168.211.133:85;
      include uwsgi_params;
      uwsgi_pass   0.0.0.0: 8080;root   /crm/;
      index  index.html index.htm;
    }
    location /static {
      #与步骤4配置静态资源中STATIC_URL相对应     
      alias /crm/my_static/;
    }

    error_page  404             /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   html;
    }


  }
  server {
    listen  85;
    server_name  localhost;
    charset utf-8;
    location / {
      root   /crm85/;
      index  index.html index.htm;
    }
  }
  
}

步骤4.配置静态资源

进入 $Home//document/CRM/crm/crm/ 目录 setting.py增加如下

STATIC_URL = '/crm/my_static/'

进入manage.py所在目录,运行如下命令即可

python manage.py collectstatic

步骤5.启动项目

#启动supervisor
supervisord -c /etc/supervisord.conf 
#启动crm(crm与步骤二中的[program:crm]相对应)
supervisorctl start crm
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值