前提
已经安装好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



