安装gunicorn
pip install gunicorn
查看命令选项
guniorn -h
调试执行命令
gunicorn -w 4 -b 192.168.31.113:5000 --access-logfile ./logs/log api:app
运维终端执行命令
# cd 到目录
gunicorn -w 4 -b 192.168.31.113:5000 -D --access-logfile ./logs/log api:app
gunicorn 查看后台进程
ps aux | grep gunicorn
dragon 27866 0.0 0.2 4272808 20760 ?? S 11:38AM 0:00.23 /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python /Users/dragon/.virtualenvs/WebApi/bin/gunicorn -w 4 -b 127.0.0.1:5000 --access-logfile ./logs/log api:app
dragon 27865 0.0 0.2 4272808 20812 ?? S 11:38AM 0:00.22 /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python /Users/dragon/.virtualenvs/WebApi/bin/gunicorn -w 4 -b 127.0.0.1:5000 --access-logfile ./logs/log api:app
dragon 27864 0.0 0.2 4272808 20732 ?? S 11:38AM 0:00.23 /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python /Users/dragon/.virtualenvs/WebApi/bin/gunicorn -w 4 -b 127.0.0.1:5000 --access-logfile ./logs/log api:app
dragon 27863 0.0 0.2 4272808 20708 ?? S 11:38AM 0:00.23 /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python /Users/dragon/.virtualenvs/WebApi/bin/gunicorn -w 4 -b 127.0.0.1:5000 --access-logfile ./logs/log api:app
dragon 27749 0.0 0.2 4265372 20896 ?? S 11:36AM 0:00.51 /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python /Users/dragon/.virtualenvs/WebApi/bin/gunicorn -w 4 -b 127.0.0.1:5000 --access-logfile ./logs/log api:app
dragon 28075 0.0 0.0 4268176 536 s002 R+ 11:40AM 0:00.00 grep gunicorn
杀死gunicorn进程
# 延迟时间较长,耐心等待
kill -9 28075
Nginx配置,在http中找到以下配置信息,upstream配置自带的参数,表示上游信息
# 多服务配置 代码在http里面,server 外面
upstream flask {
server 192.168.199.208:5000;
server 192.168.199.208:5001;
}
server {
listen 8000; # 端口不能用80和8080,已经被nginx占用,除非更改默认
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://flask; #收到的请求进行转发
proxy_set_header Host $host;
proxy_set_header X-real-IP $remote_addr;
root html;
index index.html index.htm;
}
brew 操作nginx命令:启动,重启,关闭
# 启动
brew services start nginx
# 重启
brew services restart nginx
# 关闭
sudo brew services stop nginx
nginx 配置文件 测试
# 测试配置文件
nginx -t
# 出现一下代码则表示测试通过
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
查看端口是否被占用
sudo lsof -i:8080
网友评论