【发布时间】:2026-02-14 00:30:01
【问题描述】:
问题
我有一个用 python 编写的简单烧瓶应用程序,我想在 Windows Server 2019 机器上使用 IIS 托管它。
该应用已经使用 Flask 附带的开发服务器在本地运行。此外,完全相同的代码在我的 windows-server 2016 机器以及我的 Windows7 工作站上完美运行。
当我尝试在我的 Windows server 2019 机器上的 IIS 下运行它时,它会出现错误 500 -“FastCGI 意外退出”,令人沮丧。我尝试了各种各样的事情,但一无所获。希望有人能帮忙!
设计
该应用程序是此 Microsoft 网页中描述的 wfastcgi 方法的实现: https://docs.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2019
python脚本是
app_hello.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return ' Hello, world!!!'
if __name__ == "__main__":
app.run()
web.config 文件是
web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="c:\devel\a_anomaly_detection\.venv\scripts\python.exe|c:\devel\a_anomaly_detection\.venv\lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<tracing>
<traceFailedRequests>
<add path="*">
<traceAreas>
<add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,WebSocket" verbosity="Verbose" />
</traceAreas>
<failureDefinitions timeTaken="00:00:00" statusCodes="500" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="app_hello.app" />
<add key="PYTHONPATH" value="c:\devel\a_anomaly_detection\website" />
<add key="WSGI_LOG" value="c:\devel\a_anomaly_detection\data\logs\wfastcgi.log" />
</appSettings>
</configuration>
我的软件版本是
-
Windows 服务器 2019
-
IIS 10
-
python 3.7.6rc1
-
wfastcgi 3.0.0
-
烧瓶 1.1.2
错误 500 页面
[error_500_screen][1]
tracefailedRequests
我启用了 tracefailedRequests,这是报告的内容
-
NOTIFY_MODULE_START ModuleName="FastCgiModule", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotification="false" 09:08:17.333
-
FASTCGI_ASSIGN_PROCESS CommandLine="c:\devel\a_anomaly_detection.venv\scripts\python.exe c:\devel\a_anomaly_detection.venv\lib\site-packages\wfastcgi.py", IsNewProcess="true", ProcessId=" 3708", RequestNumber="1" 09:08:17.333
-
FASTCGI_START 09:08:17.333
-
FASTCGI_WAITING_FOR_RESPONSE 09:08:17.333
-
FASTCGI_UNEXPECTED_EXIT 错误 09:08:17.349
-
SET_RESPONSE_ERROR_DESCRIPTION 警告 ErrorDescription="c:\devel\a_anomaly_detection.venv\scripts\python.exe - FastCGI 进程意外退出" 09:08:17.349
-
MODULE_SET_RESPONSE_ERROR_STATUS 警告 ModuleName="FastCgiModule", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="无法再次设置信号量。 (0x67)", ConfigExceptionInfo="" 09:08:17.349
-
NOTIFY_MODULE_END ModuleName="FastCgiModule", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_FINISH_REQUEST" 09:08:17.349
【问题讨论】:
-
所以 Flask 不是一个 CGI 框架,它是一个 WSGI 框架。我的个人经验是使用
gunicorn包来运行烧瓶服务器,然后使用 NGINX/IIS/托管 that。
标签: flask iis fastcgi wfastcgi