Windows Server 2012上的Flask,wfastcgi和IIS

时间:2018-03-23 01:31:25

标签: python iis flask wfastcgi

我正在尝试在Windows Server 2012上的IIS上部署刻录服务。到此为止:

  1. pip安装烧瓶(已安装Python版本2.7和3。)
  2. pip安装了wfastcgi
  3. Ran wfastcgi-enable
  4. 在IIS
  5. 下建立了一个新网站
  6. 为wfastcgi
  7. 添加了一个处理程序
  8. 修改了Web.config
  9. 从localhost运行会返回我期望的输出。但是,当我从网站名称访问网站时,会返回以下错误(路径省略):

    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
    

    无论是在服务器上还是在域上的其他计算机上都是如此。似乎除了localhost之外的任何应用程序请求应用程序时,环境无法访问。什么都没有写入wfastcgi日志。

    我在下方添加了app.pyWeb.config。我在这里省略了scriptProcessor路径,但它被设置为从wfastcgi-enable返回的值。

    从localhost运行时,环境可用。 如果在locahost之外调用,该如何使应用环境可用?

    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

    <?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>
    

1 个答案:

答案 0 :(得分:3)

最近我们遇到了类似的问题,包括IIS 7,Flask 0.12和Python 3.6.4。你的web.config看起来不错。两条建议:

  1. 使用virtualenv作为脚本处理器
  2. 在IIS中仔细检查IIS_IUSRS和IUSR是否已修改Python路径中文件夹的权限。
相关问题