uwsgi+nginx+django生产环境部署

1、升级python到2.7版本

2、安装uwsgi

  出现uwsgi未找到

yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
yum install python-devel
yum install gcc
pip install uwsgi
uwsgi --version

3、测试wusgi是否正常(uwsgi --http ip:port --file project/wsgi.py --static-map=/static=static)

4、写uwsgi配置文件(启动命令:uwsgi --ini uwsgi.ini,停止命令uwsgi --stop uwsgi.pid)

     uwsgi配置文件

  [uwsgi]
  # 项目目录
  chdir=app文件夹
  # 启动uwsgi的用户名和用户组
  uid=root
  gid=root
  # 指定项目的application
  module=comweb.wsgi:application
  # 指定sock的文件路径
  socket=/www/XXXXXX/XXXXXX/uwsgi.sock
  # 启用主进程
  master=true
  # 进程个数
  workers=5
  pidfile=/www/XXXXXX/uwsgi.pid
  #ip端口
  #http=172.16.252.53:80
  #指定静态文件

  # 自动移除unix Socket和pid文件当服务停止的时候
  vacuum=true
  # 序列化接受的内容,如果可能的话
  thunder-lock=true
  # 启用线程
  enable-threads=true
  # 设置自中断时间
  harakiri=30
  # 设置缓冲
  post-buffering=1024
  # 设置日志目录
  daemonize=/www/XXX/XXX/uwsgi.log

5、配置nginx yum源

  在/etc/yum.repos.d/目录下添加.nginx.repo文件

  [nginx]
  name=nginx repo
  baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
  gpgcheck=0
  enabled=1

6、yum安装nginx

7.在/etc/nginx/conf.d/目录下添加XXX.conf文件

server {
listen 80;
server_name 103.214.168.94;
#access_log /var/log/nginx/access.log main;
charset utf-8;
gzip on;
gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
# 指定项目路径uwsgi
location / {
include uwsgi_params;
uwsgi_connect_timeout 30;
uwsgi_pass unix:/www/XXX/script/uwsgi.sock;
}
# 指定静态文件路径
location /static/ {
alias /www/XXX/comweb/static_all/;
index index.html;

}

}

8、启动uwsgi  nginx

9、收集资源到static_all文件夹

在django settings.py文件中设置static_root路径

STATIC_ROOT = os.path.join(BASE_DIR,'static_all')

python manage.py collectstatic

 

posted @ 2018-06-21 17:53  破晓e  阅读(160)  评论(0编辑  收藏  举报