Centos7 Flask+gunicorn+nginx+supervisor 简单配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/okm6666/article/details/80676910

这里写图片描述

Nginx 监听的端口收到来自客户端的请求,根据配置文件转发给WSGI
WSGI调用flask框架生成对应路由的html,发送给Nginx
Nginx将响应发送给客户端

【Nginx】
1.安装

yum install nginx

2.修改配置文件

server {
        listen 80;
        server_name _; # 外部地址
        location / {
                proxy_pass http://127.0.0.1:8000;
                proxy_redirect     off;
                proxy_set_header   Host                 $http_host;
                proxy_set_header   X-Real-IP            $remote_addr;
                proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Proto    $scheme;
        }

【Gunicorn】
WSGI容器启动flask的web应用实例
启动file路径下的app,app在文件中定义app = Flask(name), -w 是指开启几个worker

gunicorn -w 1 file:app  

【supervisor】配置文件管理进程
1.安装

pip install supervisor

2.生成配置文件

echo_supervisord_conf  > ~/supervisord.conf (把配置文件生成到指定位置)

3.在配置文件中中指定包含的文件(目标项目的配置文件)
在文件底部编辑:

[include]
files = /项目路径/*.conf

4.编辑具体命令配置文件 https://www.jianshu.com/p/0226b7c59ae2
根据在配置文件中指定的路径编辑对应文件

[program:项目名]
command= 命令
directory= 执行命令的目录
autostart= 自动开启
autorestart= 自动重启
stdout_logfile= 输出log地址
stderr_logfile= 错误log地址

5.启动supervisor

supervisord -c ~/supervisor.conf

6.开启对应项目

supervisorctl -c supervisor.conf start 项目名
<常用命令>:
supervisord -c supervisor.conf  通过配置文件启动
supervisorctl -c supervisor.conf status 查看状态 
supervisorctl -c supervisor.conf reload 重新载入配置文件 
supervisorctl -c supervisor.conf start [all]|[x] 启动所有/指定的程序进程 
supervisorctl -c supervisor.conf stop [all]|[x] 关闭所有/指定的程序进程

猜你喜欢

转载自blog.csdn.net/okm6666/article/details/80676910
今日推荐