Windows Server 2012上的烧瓶,wfastcgi和IIS [英] Flask, wfastcgi, and IIS on Windows Server 2012

查看:341
本文介绍了Windows Server 2012上的烧瓶,wfastcgi和IIS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows Server 2012的IIS上部署Flask服务.要达到这一点:

I am trying to deploy a flask service on IIS on Windows Server 2012. To arrive at this point:

  1. pip安装的烧瓶(已经安装了python版本2.7和3.)
  2. pip已安装wfastcgi
  3. 启用wfastcgi启用
  4. 在IIS下建立新站点
  5. 为wfastcgi添加了处理程序
  6. 修改后的Web.config

从localhost运行会返回我期望的输出.但是,当我从站点名称访问该网站时,返回以下错误(路径省略):

Running from localhost returns the output I expect. However, when I visit the website from the sitename, the following error is returned (paths omitted):

Error occurred while reading WSGI handler:

Traceback (most recent call last):
  File "wfastcgi.py", line 791, in main
    env, handler = read_wsgi_handler(response.physical_path)
  File "wfastcgi.py", line 633, in read_wsgi_handler
    handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
  File "wfastcgi.py", line 586, in get_wsgi_handler
    raise Exception('WSGI_HANDLER env var must be set')
Exception: WSGI_HANDLER env var must be set

无论是在服务器上还是在域中的另一台机器上,都是这种情况.似乎当从本地主机以外的任何地方请求该应用程序时,环境是不可访问的.什么也没有写到wfastcgi日志中.

This is the case whether on the server or from another machine on the domain. It seems as though when the app is requested from anything but localhost, the environment is unreachable. Nothing gets written to the wfastcgi log.

我在下面包括了app.pyWeb.config.我在这里省略了scriptProcessor路径,但是它设置为wfastcgi-enable返回的值.

I have included app.py and Web.config below. I omitted the scriptProcessor path here, but it is set to the value returned from wfastcgi-enable.

从本地主机运行时,环境可用. 在locahost之外调用应用程序时,如何使环境对应用程序可用?

When running from localhost, the environment is available. How do I make the environment available to the app when called beyond locahost?

app.py

app.py

from flask import Flask  
myapp = Flask(__name__)

@myapp.route("/hello") 
def hello():
  return "Hello from flask!"

if __name__ == "__main__":        
  myapp.run(port=8080)

Web.config

Web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appSettings>
        <add key="WSGI_HANDLER" value="app.myapp" />
        <add key="PYTHONPATH" value="c:/inetpub/wwwroot/flask-services/" />
        <add key="WSGI_LOG" value="C:/TMP/logs/app.log" />
    </appSettings>
    <system.webServer>
        <handlers>
            <add name="python-wfastcgi" path="*" verb="*" modules="FastCgiModule" scriptProcessor="[Omitted]" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
    </system.webServer>
</configuration>

推荐答案

我们最近在IIS 7,Flask 0.12和Python 3.6.4中遇到了类似的问题.您的web.config看起来不错.两个建议:

We had a similar problem recently with IIS 7, Flask 0.12 and Python 3.6.4. Your web.config looks good. Two recommendations:

  1. virtualenv用于脚本处理器.它避免了使用系统级Python安装带来的副作用.这样调试起来更容易.
  2. 再次在IIS中检查IIS_IUSRS和IUSR对您的Python路径中的文件夹具有修改权限.
  1. Use a virtualenv for your script processor. It avoids side-effects from using a system-level Python installation. It's easier to debug that way.
  2. Double check in IIS that IIS_IUSRS and IUSR have modify permissions for the folders in your Python path.

这篇关于Windows Server 2012上的烧瓶,wfastcgi和IIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆