Django+supervisor+gunicorn+nginx部署

一、centos7 安装 Nginx

1. 添加源
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2. 安装Nginx
# 使用命令,看看是否已经添加源成功
yum search nginx
# 如果成功则执行下列命令安装Nginx
sudo yum install -y nginx
3. 设置开机自启
systemctl enable nginx

二、安装gunicorn、supervisor

pip install gunicorn
pip install supervisor

三、生成supervisor配置文件

echo_supervisord_conf > etc/supervisord.conf

四、在supervisord.conf引入配置文件params.ini

五、修改supervisor配置文件

[program:params]
command=/home/yangxing/We_venv/bin/gunicorn -w 4  WeChat.wsgi:application -b 127.0.0.1:7000
directory=/home/yangxing
environment=ENV="server"
user=root
autostart=true
autorestart=true
stopsignal=QUIT
stopasgroup=true
killasgroup=true
stdout_logfile=/home/yangxing/log/wechat.log
stdout_logfile_maxbytes=5MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=5MB   ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false   ; emit events on stdout writes (default false)

六、使用指定路径的supervisor配置文件

sudo supervisord -c /home/yangxing/We_venv/bin/supervisord.conf

七、配置Nginx配置文件

vi /etc/nginx/conf.d/default.conf

server {
      listen 80;
      server_name  IP;
      location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://127.0.0.1:7000;
      }

      location /static {
            alias   /home/yangxing/static/;

            # Set the static file cache expiration time to 30 days
            expires  30d;
      }
}

八、重启Nginx服务

nginx -t
nginx -s reload

文章作者: 有梦想的咸鱼
版权声明: 咳咳想白嫖文章?本文章著作权归作者所有,任何形式的转载都请注明出处。 http://www.trisomy.cn !
还能输入 100 字
  目录