V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
biexiawo
V2EX  ›  Python

Flask 应用程序如何部署到服务器?

  •  1
     
  •   biexiawo · Apr 1, 2016 via Android · 20035 views
    This topic created in 3680 days ago, the information mentioned may be changed or developed.
    项目已经写好,但不了解如何部署到服务器,求哪位朋友帮忙指导下,如果有这方面的教程或者博客就太好了
    29 replies    2018-07-26 15:05:15 +08:00
    tvallday
        1
    tvallday  
       Apr 1, 2016
    根据我的经验,你需要一个 web server ,还要有反向代理 Nginx ,你也可以不用 Nginx ,但是现在这么流行学学也没坏处。 web server 我用的是 Unicorn.
    在 Google 上搜 Gunicorn flask server 。你就能找到答案。
    tvallday
        2
    tvallday  
       Apr 1, 2016
    写错,应该是 Gunicorn 不是 Unicorn , Unicorn 是 Ruby 的 server 。还有其他的 server 你也可以看一下。当然你最好把 Gunicorn 启动加到 system service 里面去,然后你就可以 sudo systemctl gunicorn start 启动了。当然添加 system service 也有很多种办法, GoogleForWhatYouWant.
    csdreamdong
        3
    csdreamdong  
       Apr 1, 2016
    apache + mod_wsgi
    biexiawo
        4
    biexiawo  
    OP
       Apr 1, 2016
    @tvallday Thank you very much !!
    biexiawo
        5
    biexiawo  
    OP
       Apr 1, 2016
    @csdreamdong 官方文档就是推荐的这种方法,但其介绍的太简略
    Kilerd
        6
    Kilerd  
       Apr 1, 2016
    nginx uwign/gunicorn gevent superivor 一套搞定。
    biexiawo
        7
    biexiawo  
    OP
       Apr 1, 2016
    @Kilerd 朋友能给推荐个教程吗?感激不尽
    aiver
        8
    aiver  
       Apr 1, 2016
    一般是 Nginx + Gunicorn + Supervisor + Flask 部署,这里有一个在阿里云上部署的例子,你可以参考: http://www.simpleapples.com/2015/06/configure-nginx-supervisor-gunicorn-flask/,我之前也是在阿里云上部署的
    clino
        9
    clino  
       Apr 1, 2016
    uwsgi 也很不错,跟 nginx 配合起来用
    lhbc
        10
    lhbc  
       Apr 1, 2016 via Android
    uwsgi, 搜索一下就有文档,非常简单。
    uwsgi 是多进程的,简单成熟。
    yjd
        11
    yjd  
       Apr 1, 2016
    重点是安全,不然就等着被 xx 了。
    crazyxin1988
        12
    crazyxin1988  
       Apr 1, 2016
    virtualenv+supervisor+nginx+gunicorn
    strahe
        13
    strahe  
       Apr 1, 2016
    搜一下 uwsgi + nginx 教程很多.
    wellsc
        14
    wellsc  
       Apr 1, 2016
    官方文档和《 flask web 开发》不是教了你 N 种方法吗?伸手就行了
    biexiawo
        15
    biexiawo  
    OP
       Apr 1, 2016
    @crazyxin1988 部署好了,用你的这个方法, 3Q !
    biexiawo
        16
    biexiawo  
    OP
       Apr 1, 2016
    @Kilerd 恩,谢谢你的指导!
    biexiawo
        17
    biexiawo  
    OP
       Apr 1, 2016
    @clino 嗯嗯,我还很菜但我会努力学的,谢谢!
    biexiawo
        18
    biexiawo  
    OP
       Apr 1, 2016
    @csdreamdong 谢谢!
    biexiawo
        19
    biexiawo  
    OP
       Apr 1, 2016
    @wellsc 嗯,我还要努力,谢谢
    Abirdcfly
        20
    Abirdcfly  
       Apr 2, 2016
    给一个新浪云 SAE 部署的例子: http://abirdcfly.github.io/2016/03/07/flask-to-sae/
    KgM4gLtF0shViDH3
        21
    KgM4gLtF0shViDH3  
       Apr 2, 2016 via iPhone
    youtube 搜 flask tutorial 就有了,一步一步教的。那小伙的教程都不错。
    biexiawo
        22
    biexiawo  
    OP
       Apr 2, 2016 via Android
    @bestkayle 👍 谢了
    zwzmzd
        23
    zwzmzd  
       Apr 2, 2016 via Android   ❤️ 1
    一般来讲 uwsgi 就够了。
    以下是我生产环境的配置,供参考

    uwsgi --http ":8080" --wsgi-file index.uwsgi --master --processes=5 --uid nobody --listen 5000 --static-map /static=static/
    clockwerk
        24
    clockwerk  
       Apr 2, 2016 via iPhone
    用 python3 开发的,正在 ngnix gunicorn ,但是卡在 python3 不支持 supervisor 上了
    zvDC
        25
    zvDC  
       Apr 2, 2016
    嗯,还在看 flask web
    zonghua
        26
    zonghua  
       Apr 4, 2016 via iPhone
    @zwzmzd 竟然生产环境也用 http ,你不用守护进程?这都是前台进程啊
    struggling
        27
    struggling  
       Jan 6, 2017
    请问你们有用 Windows 部署成功的吗?感觉 Windows 好多坑。。
    geek123
        28
    geek123  
       Mar 12, 2018
    推荐一个 flask 的入门教程给大家,讲的挺清楚:

    http://xc.hubwiz.com/course/562427361bc20c980538e26f?affid=20180312v2ex
    gevin
        29
    gevin  
       Jul 26, 2018
    我最近写了一篇相关的博客,不知对你有没有帮助

    https://blog.igevin.info/posts/how-to-deploy-flask-apps/
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1103 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 82ms · UTC 18:28 · PVG 02:28 · LAX 11:28 · JFK 14:28
    ♥ Do have faith in what you're doing.