通过supervisor管理gunicorn、nginx进程

通过supervisor管理进程

方式一:Web界面

supervisord.conf中配置

[inet_http_server]
port=127.0.0.1:9001

再运行supervisord -c supervisord.conf

最后用浏览器打开 http://127.0.0.1:9001 进行管理

方式二:命令行

查看所有进程状态

supervisorctl status

启动所有进程

supervisorctl start all

关闭所有进程

supervisorctl stop all

重启所有进程

supervisorctl restart all

启动指定进程supervisorctl start [进程名]

supervisorctl start nginx
supervisorctl start gunicorn

关闭指定进程supervisorctl stop [进程名]

supervisorctl stop nginx
supervisorctl stop gunicorn

重启指定进程supervisorctl restart [进程名]

supervisorctl restart nginx
supervisorctl restart gunicorn

关闭 supervisord(先stop all再shutdown)

supervisorctl stop all
supervisorctl shutdown
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nginx是一个高性能的HTTP和反向代理服务器,可以用来处理静态文件和动态请求。gunicorn是一个Python WSGI HTTP服务器,可以将Flask应用程序部署到生产环境中。supervisor是一个进程控制系统,可以用来管理监控进程。这三个工具可以一起使用来部署Flask应用程序。 以下是使用nginxgunicornsupervisor部署Flask应用程序的步骤: 1. 安装nginxgunicornsupervisor。 2. 编写Flask应用程序,并使用工厂函数构建应用程序对象。 3. 创建一个gunicorn配置文件,例如gunicorn.conf.py,指定工作进程数和线程数。 4. 使用gunicorn启动Flask应用程序,例如: ```shell gunicorn -c gunicorn.conf.py "my_project:create_app()" ``` 这将启动一个gunicorn进程,监听8000端口,并将请求转发到Flask应用程序。 5. 配置nginx,将请求转发到gunicorn进程。例如,在nginx.conf文件中添加以下内容: ```nginx server { listen 80; server_name example.com; location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ``` 这将将所有请求转发到gunicorn进程,并将请求头中的一些信息传递给Flask应用程序。 6. 使用supervisor管理gunicorn进程。例如,在supervisor.conf文件中添加以下内容: ```ini [program:gunicorn] command=/path/to/gunicorn -c /path/to/gunicorn.conf.py "my_project:create_app()" directory=/path/to/project user=user autostart=true autorestart=true stopasgroup=true killasgroup=true ``` 这将启动一个名为gunicorn进程,并在系统启动时自动启动该进程。如果该进程崩溃或被杀死,supervisor将自动重新启动该进程
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值