Flask web專案 gunicorn部署

oktokeep發表於2024-05-01

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

相關文章