美文网首页
flask项目在Linux上部署

flask项目在Linux上部署

作者: 百分百空手接白刃_566c | 来源:发表于2021-08-27 14:47 被阅读0次

    有两种部署方式:

    1. flask run的方式
    2. 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访问
    #-p 8888 端口号
    # nohup flask run -h 0.0.0.0 -p 8888  2>&1 &. 后台运行
    

    uwsgi 部署的方式

    创建一个app.ini文件

    # app.ini
    [env]
    env=dev
    
    [uwsgi]
    master = true
    # 以下几个配置使用uWSGI可以动态根据负载扩展使用的进程数
    # 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
    # 直接启动web服务   要借助nginx 用socket socket = 0.0.0.0:13001 
    http = 0.0.0.0:13001 
    chmod-socket = 666
    #在退出uwsgi环境后,清空环境变量
    vacuum = true
    die-on-term = true
    callable = app
    module = xxx.wsgi
    logger = file:///home/xxx/.log
    buffer-size = 32768
    http-timeout = 1200
    # 后台启动
    daemonize = yes
    wsgi-file=/home/xxx/wsgi.py
    pidfile=/home/xxx/xxx.pid
    

    命令行:

    cd myapp-admin
    source venv/bin/activate
    uwsgi --ini app.ini # 启动
    

    启动成功之后会有一个.pid文件

    # 重启:
    uwsgi --reload xxx.pid
    # 停止:
    uwsgi --stop xxx.pid
    

    相关文章

      网友评论

          本文标题:flask项目在Linux上部署

          本文链接:https://www.haomeiwen.com/subject/swsmiltx.html