我正在尝试在 Windows Server 2012 上的 IIS 上部署烧瓶服务。要达到这一点:
- pip installed flask(Python 版本 2.7 和 3 已安装。)
- pip 安装 wfastcgi
- 跑 wfastcgi-enable
- 在IIS下建立一个新站点
- 为 wfastcgi 添加了一个处理程序
- 修改后的 Web.config
从 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.py
下面Web.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>