Nginx+Gunicorn+Supervisor

1、使用 Gunicorn

Gunicorn是一个unix上被广泛使用的高性能的Python WSGI UNIX HTTP Server。它和大多数的web框架兼容,并具有实现简单,轻量级,高性能等特点

pip3 install gunicorn

2、启动 Nginx

Nginx 的配置位于 /etc/nginx/nginx.conf 文件中


user nobody nobody;
...
http {
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
 
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
 
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
 
        location / {
        }
    }
}

 


3、使用Supervisor

Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启

如果更换了代码,就进去supervisorctl 执行update就好了

https://www.zmrenwu.com/courses/django-blog-tutorial/materials/74/

https://www.bilibili.com/video/BV1RJ411c7KD?from=search&seid=6979336520627324888

 

相关配置说明

Mysql

  1. setting.py中DATABASES修改配置
  2. 在__init__.py中添加模块

Gunicorn

  1. setting.py中WSGI_APPLITION修改
  2. wsgi.py修改

Nginx

  1. setting.py中ALLOWED_HOSTS添加主机
  2. 修改/etc/nginx/conf.d/newyolo.conf

Supervisor

  1. 创建/etc/supervisord.conf文件
  2. 创建/etc/supervisor文件目录,里面包含log和配置网站信息