django 生产环境部署

使用nginx+uwsgi实现django生产环境的部署

部署环境

  • 系统: ubuntu 18.04
  • uwsgi + django + nginx

部署过程

python虚拟环境安装配置

暂无

django配置

暂无

uwsgi安装配置

  1. 安装uwsgi并进行测试
uwsgi --http 0.0.0.0:9099 --chdir /root/dj-sites/yuTa/yuTa/projects --module projects.wsgi --home /root/dj-sites/yuTa/venv
  • http 指定端口号
  • chdir 指定工程路径,即manager.py所在路径
  • module 用于指定wsgi.py文件相对工程路径的位置
  • home 指定虚拟机所在路径
  1. 配置uwsgi.ini文件
[uwsgi]
chdir           = /root/dj-sites/yuTa/yuTa/projects
module          = projects.wsgi
master          = true
processes       = 4
socket          = /root/dj-sites/yuTa/yuTa.sock
#http            = :9099
vacuum          = true
home            = /root/dj-sites/yuTa/venv

stats           = /root/dj-sites/yuTa/uwsgi.status
pidfile         = /root/dj-sites/yuTa/uwsgi.pid
  1. uwsgi命令
  • 启动:uwsgi --ini xxx.ini
  • 重启:uwsgi --reload xxx.pid
  • 停止:uwsgi --stop xxx.pid

nginx配置

/etc/nginx/sites-available路径下创建yuTa_nginx

upstream django {
        server 127.0.0.1:9092;
}
server {
        listen      80;
        server_name yuTa.lazyboy.site;
        charset     utf-8;

        client_max_body_size 75M;   # adjust to taste
        location /media  {
            alias /root/dj-sites/yuTa/yuTa/projects/media;
        }
        location /static {
            alias /root/dj-sites/yuTa/yuTa/projects/static;
        }
        location / {
            uwsgi_pass  django;
            include     /etc/nginx/uwsgi_params;
        }
}

然后执行
执行ln -s yuTa_nginx ../sites-enabled/yuTa_nginx使其生效

https配置

暂无