Flask 部署


2021-04-04 Flask

# 普通项目部署

# 使用 Gunicorn 部署

部署前说明:项目使用 pipenv 作为项目环境与依赖管理工具。

开始部署,

  1. 安装 gunicorn

    pipenv install gunicorn
    

    注:最好先改一下 Pipfile 中的依赖包下载源,

    [[source]]
    url = "https://pypi.tuna.tsinghua.edu.cn/simple"   // 清华源
    
  2. 执行如下命令

    gunicorn -w 4 -b 0.0.0.0:3000 -D --access-logfile ./logs/log main:app
    
    • -w 4 表示 work process 数量 (进程数量)
    • -b 绑定主机和端口号
    • -D 守护进程
    • --access-logfile 日志文件存储位置
    • main:app 代表运行 main 文件(模块)里的名字为 app 的 flask 实例
Last Updated: 4/9/2021, 8:49:34 AM