有兩種部署方式:
- flask run的方式
- uwsgi 部署
flask run的方式:
目錄下必須有程序入口wsgi.py 或者是 run.py
image.png
cd myapp-admin
source venv/bin/activate
flask run -h 0.0.0.0 -p 8888
# -h 0.0.0.0 web訪(fǎng)問(wèn)
#-p 8888 端口號(hào)
# nohup flask run -h 0.0.0.0 -p 8888 2>&1 &. 后臺(tái)運(yùn)行
uwsgi 部署的方式
創(chuàng)建一個(gè)app.ini文件
# app.ini
[env]
env=dev
[uwsgi]
master = true
# 以下幾個(gè)配置使用uWSGI可以動(dòng)態(tài)根據(jù)負(fù)載擴(kuò)展使用的進(jìn)程數(shù)
# set cheaper algorithm to use, if not set default will be used
cheaper-algo = spare
chdir = /home/xxx
# minimum number of workers to keep at all times
cheaper = 2
# number of workers to spawn at startup
cheaper-initial = 2
# maximum number of workers that can be spawned
workers = 4
# how many workers should be spawned at a time
cheaper-step = 1
# 直接啟動(dòng)web服務(wù) 要借助nginx 用socket socket = 0.0.0.0:13001
http = 0.0.0.0:13001
chmod-socket = 666
#在退出uwsgi環(huán)境后籍救,清空環(huán)境變量
vacuum = true
die-on-term = true
callable = app
module = xxx.wsgi
logger = file:///home/xxx/.log
buffer-size = 32768
http-timeout = 1200
# 后臺(tái)啟動(dòng)
daemonize = yes
wsgi-file=/home/xxx/wsgi.py
pidfile=/home/xxx/xxx.pid
命令行:
cd myapp-admin
source venv/bin/activate
uwsgi --ini app.ini # 啟動(dòng)
啟動(dòng)成功之后會(huì)有一個(gè).pid文件
# 重啟:
uwsgi --reload xxx.pid
# 停止:
uwsgi --stop xxx.pid