【问题标题】:How to deploy a Flask application in IIS 8 (Windows Server 2012)如何在 IIS 8 (Windows Server 2012) 中部署 Flask 应用程序
【发布时间】:2013-11-21 23:50:00
【问题描述】:

如何在 IIS 8 (Windows Server 2012) 中部署 Flask 应用程序?周围有很多部分解释,但似乎没有任何作用。

【问题讨论】:

    标签: python iis flask iis-8


    【解决方案1】:

    以防万一。对于复杂而重要的应用程序,我不会在生产环境中做任何事情。

    我会选择反向代理 + gunicorn。这就是我现在大部分时间都在做的事情,但是使用 nginx 和 linux 机器。这里的问题是 gunicorn 目前不支持 windows (but support is planned)。现在您可以选择在 Cygwin 中使用 gunicorn 运行您的 Flask 应用程序。

    另一种方法是尝试这个https://serverfault.com/questions/366348/how-to-set-up-django-with-iis-8,而不是Django相关的东西,特别是

    from django.core.handlers.wsgi import WSGIHandler as DjangoHandler
    

    你需要你的 Flask 路径和环境变量和

    from yourapplication import app as FlaskHandler
    

    注意:您可以尝试使用here 列出的其他启动器,而不是 gunicorn。 Windows 上的 Twisted 或 Tornado 可能会带来更多的运气

    更新:Cygwin 中的 Gunicorn

    我在 Window 7 64bit 和 Cygwin 1.7.5 32bit 上。 Python 版本 2.6.8。

    我在使用 Cygwin 64 位和 Python 2.7 运行 Flask 时遇到了一些问题,尽管 gunicorn 似乎工作正常。

    你可以得到 Cygwin here

    我已安装的软件包:

    • 纳米
    • python 2.6.8
    • 卷曲

    然后我安装了 pip:

    $ curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | python
    $ easy_install pip
    

    然后是烧瓶和独角兽:

    $ pip install flask gunicorn
    

    我已经简单了app.py:

    from flask import Flask
    app = Flask(__name__)
    
    @app.route("/")
    def hello():
        return "Hello World!"
    
    if __name__ == "__main__":
        app.run()
    

    然后用 gunicorn 运行它:

    $ gunicorn app:app
    2013-11-27 16:21:53 [8836] [INFO] Starting gunicorn 18.0
    2013-11-27 16:21:53 [8836] [INFO] Listening at: http://127.0.0.1:8000 (8836)
    2013-11-27 16:21:53 [8836] [INFO] Using worker: sync
    2013-11-27 16:21:53 [6140] [INFO] Booting worker with pid: 6140
    

    之后,您需要让 gunicorn 应用像 windows service 一样运行。但是那部分我很久没做所以记忆被遮蔽了:)

    注意:如果您准备好尝试,我已经找到了另一个选项https://code.google.com/p/modwsgi/wiki/InstallationOnWindows

    【讨论】:

    • 谢谢。如果您能解释如何让它在 Windows 上运行,我很高兴尝试 gunicorn。否则,您能否提供有关如何设置其他启动器之一以及如何将其与 IIS 集成的更多详细信息?
    【解决方案2】:

    我使用 FastCGI 的这种方法取得了更大的成功:http://codesmartinc.com/2013/04/12/running-django-in-iis7iis8/

    对于WSGI_Handler 变量,只需使用(yourModule).app 而不是django.core.handlers.wsgi.WSGIHandler()

    【讨论】:

      猜你喜欢
      • 2015-03-12
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-11
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多