Flask web项目 gunicorn部署
安装
pip3 install gunicorn
查看版本及是否安装成功
flask --version
gunicorn -h
### 需要与app.py启动文件中的ip和端口号一致。
gunicorn -w 3 -b 外网IP地址XX.XX.XX.XX:8002 app:app
端口号的原因:端口号 > 8000
#启动报错
gunicorn -w 3 -b 0.0.0.0:5000 app:app
#本机地址启动
gunicorn -w 3 -b 127.0.0.1:8080 app:app
#ip地址启动(内网通过IP访问)
gunicorn -w 3 -b 外网IP地址XX.XX.XX.XX:8002 app:app
后台启动:
##定位到项目的目录
/usr/local/myFlask/myTestProject
##后台启动
nohup gunicorn -w 3 -b 外网IP地址XX.XX.XX.XX:8003 app:app > /dev/null 2>&1 &
查看进程
ps -ef | grep gunicorn
root 21913 5649 0 14:38 pts/0 00:00:00 /usr/bin/python3 /usr/local/bin/gunicorn -w 3 -b 外网IP地址XX.XX.XX.XX:8002 app:app
root 21916 21913 0 14:38 pts/0 00:00:00 /usr/bin/python3 /usr/local/bin/gunicorn -w 3 -b 外网IP地址XX.XX.XX.XX:8002 app:app
root 21917 21913 0 14:38 pts/0 00:00:00 /usr/bin/python3 /usr/local/bin/gunicorn -w 3 -b 外网IP地址XX.XX.XX.XX:8002 app:app
root 21918 21913 0 14:38 pts/0 00:00:00 /usr/bin/python3 /usr/local/bin/gunicorn -w 3 -b 外网IP地址XX.XX.XX.XX:8002 app:app
root 25867 28856 0 14:39 pts/1 00:00:00 grep --color=auto gunicorn
关闭进程
kill -9 21913