【发布时间】:2018-08-17 18:12:42
【问题描述】:
我正在尝试从默认网站下的 IIS Web 应用程序提供 Flask 应用程序,但无法使其正常工作。以下是详细信息:
OS: Windows Server 2016 DataCenter Edition
IIS: Installed with all options including CGI
IIS Rewrite Module: Version 2 installed
我已采取的步骤:
- 安装带有所有组件的 IIS(使用 CGI)
- 安装 Python 2.7.14
- 在
PATH变量中添加Python pip install wfastcgiwfastcgi-enablepip install flaskiisreset- 创建目录:
C:\inetpub\wwwroot\flask-demo - 点击 IIS 中的
Convert to Application进入上述目录。 - 使用以下内容创建
C:\inetpub\wwwroot\flask-demo\myapp.py:
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' if __name__ == "__main__": app.run()
- 使用以下内容创建
C:\inetpub\wwwroot\flask-demo\web.config:
<configuration> <system.webServer> <handlers> <remove name="Python FastCGI" /> <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python27\python.exe|C:\Python27\Lib\site-packages\wfastcgi.pyc" resourceType="Unspecified" requireAccess="Script" /> </handlers> <rewrite> <rules> <rule name="asset-url-rewrite" stopProcessing="true"> <match url="static" /> <conditions> </conditions> <action type="Rewrite" url="flask-demo/{R:0}" /> </rule> <rule name="app-url-rewrite" stopProcessing="true"> <match url="[a-zA-Z]+" /> <conditions> </conditions> <action type="Rewrite" url="flask-demo/" /> </rule> </rules> </rewrite> </system.webServer> <appSettings> <add key="WSGI_HANDLER" value="myapp.app" /> <add key="PYTHONPATH" value="C:\inetpub\wwwroot\flask-demo" /> </appSettings> </configuration>
问题
当我尝试以 http://localhost/flask-demo 访问页面时,我得到 404。但是如果我将 myapp.py 中的第二行从 @app.route('/') 更改为 @app.route('/flask-demo') 其中flask-demo 是 IIS Web 应用程序的名称,其中 Python文件已放置,它可以工作。
我希望在不写flask-demo/放置 Python 烧瓶应用程序的 IIS Web 应用程序的名称的情况下提供 Python 网页。我做不到。
我尝试使用app.config['APPLICATION_ROOT'] = '/flask-demo',但没有成功。
让这个工作的最佳方法是什么?关注文章https://medium.com/@bilalbayasut/deploying-python-web-app-flask-in-windows-server-iis-using-fastcgi-6c1873ae0ad8,但没有帮助。
【问题讨论】:
-
您不能将多个服务连接到同一个端口!请检查错误日志。请同时检查网络或环回访问权限。
-
它是 IIS 托管,从同一个端口为多个 Web 应用程序提供服务应该没有任何问题。它应该可以工作(它适用于 ASP.NET 应用程序)。这是我需要帮助的代码/方法中的问题。
-
flask 广播哪个端口?
It's IIS hosting and there should not be any problem for serving multiple web applications完全错误的想法(没有任何规则),!不要混淆 CGI 和 SERVER(服务)术语。如果ISS服务运行,则无法监听80端口! -
没有广播。如果您使用 medium.com 链接 - 它说这应该有效。在我的例子中,IIS 通过 Fast CGI 与 Python 对话。
-
1- 尝试没有应用程序的 CGI 脚本 2-检查文件权限 3-检查要触发的应用程序(python,什么是 python?) 4- ISS 不能跟随系统路径,它需要特殊授权离开给定的目录。 5-主要广播服务地址转发(ISS处理地址块>> CGI脚本)不知道错过了。