截止目前最新版本为4.7.0
pip install supervisor-win
保存名为supervisor-win.ini
的配置文件,其中port=*:9001
代表监控所有IP地址,由于windows没有办法使用uwsgi
,所以这里配置了两个program
:[program:app-win1]
和[program:app-win2]
(可以配置更多。。。),然后再使用nginx
的负载均衡功能来提高并发量
[supervisord]
nodaemon=false
environment=PYTHONIOENCODING=utf8,PYTHONUNBUFFERED=1
[inet_http_server]
port=*:9001
[supervisorctl]
[program:app-win1]
command=D:\\workspace\\flask\\flask-server\\venv\\Scripts\\python.exe D:\\workspace\\flask\\flask-server\\src\\wsgi.py 5001
autostart=true
autorestart=true
# 将stderr的日志写入stdout日志文件中
redirect_stderr=true
stdout_logfile=D:\workspace\flask\flask-server\logs\app1.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
# 杀死进程组包括子进程
stopasgroup=true
killasgroup=true
[program:app-win2]
command=D:\\workspace\\flask\\flask-server\\venv\\Scripts\\python.exe D:\\workspace\\flask\\flask-server\\src\\wsgi.py 5002
autostart=true
autorestart=true
# 将stderr的日志写入stdout日志文件中
redirect_stderr=true
stdout_logfile=D:\workspace\flask\flask-server\logs\app2.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
# 杀死进程组包括子进程
stopasgroup=true
killasgroup=true
.\venv\Scripts\python.exe -m supervisor.services install -sn flask-server -c D:\workspace\flask\flask-server\conf\supervisor-win.ini
在【服务】中设置找到flask-server
,设置为自动启动,这样重启电脑就可以自动启动了
进入http://localhost:9001
nginx.conf
upstream flaskapp {
server localhost:5001 max_fails=2;
server localhost:5002 max_fails=2;
server localhost:5003 max_fails=2;
server localhost:5004 max_fails=2;
}
server {
listen 5000;
server_name localhost;
location / {
proxy_connect_timeout 2s;
proxy_pass http://flaskapp/;
}
}