IIS 上的 Python flask 应用程序无法在 Windows Server 2019 上运行

问题描述 投票:0回答:2

问题

我有一个用 python 编写的简单 flask 应用程序,我想在 Windows Server 2019 机器上使用 IIS 托管它。

应用程序已经使用 Flask 自带的开发服务器在本地运行。此外,完全相同的代码在我的 window-server 2016 机器和我的 Windows7 工作站上都能完美运行。

令人沮丧的是,当我尝试在我的 Windows Server 2019 机器上的 IIS 下运行它时,它会出现错误 500 - “FastCGI 意外退出”。我已经尝试了各种各样的事情,但没有任何进展。我希望有人能帮忙!

设计

该应用程序是此 Microsoft 网页中描述的 wfastcgi 方法的实现: https://learn.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

  • 蟒蛇3.7.6rc1

  • wfastcgi 3.0.0

  • 烧瓶 1.1.2

错误500页

[error_500_screen][1]

tracefailedRequests

我启用了tracefailedRequests这就是报告的内容

  1. NOTIFY_MODULE_START ModuleName="FastCgiModule", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotification="false" 09:08:17.333

  2. FASTCGI_ASSIGN_PROCESS CommandLine="c:\devel_anomaly_detection.venv\scripts\python.exe c:\devel_anomaly_detection.venv\lib\site-packages\wfastcgi.py", IsNewProcess="true", ProcessId="3708 ", RequestNumber="1" 09:08:17.333

  3. FASTCGI_START 09:08:17.333

  4. FASTCGI_WAITING_FOR_RESPONSE 09:08:17.333

  5. FASTCGI_UNEXPECTED_EXIT 错误 09:08:17.349

  6. SET_RESPONSE_ERROR_DESCRIPTION 警告 ErrorDescription="c:\devel _anomaly_detection.venv\scripts\python.exe - FastCGI 进程意外退出" 09:08:17.349

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

  8. NOTIFY_MODULE_END ModuleName="FastCgiModule", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_FINISH_REQUEST" 09:08:17.349

flask iis fastcgi wfastcgi
2个回答
0
投票

您很可能忘记在服务器上为您的虚拟环境安装 Python。查看

c:\devel\a_anomaly_detection\.venv\pyvenv.cfg
文件并检查文件夹中是否确实有 Python,指定为 home 参数。

要排除故障,请从 c:\devel _anomaly_detection\website 文件夹运行此命令:

c:\devel\a_anomaly_detection\.venv\scripts\python.exe c:\devel\a_anomaly_detection\.venv\lib\site-packages\wfastcgi.py
并检查它的输出


0
投票

我知道这是一个旧线程,但我刚刚处理了类似设置中的内部服务器 500 错误,希望这些链接将来能帮助其他人。

我按照这里的指南开始:https://medium.com/@dpralay07/deploy-a-python-flask-application-in-iis-server-and-run-on-machine-ip-address -ddb81df8edf3

在尝试导入其他 python 模块(pandas / numpy)后我仍然遇到问题,结果我需要将我的 PATH 变量添加到我的 FastCGI 设置中(正如其他人在这里提到的:numpy 已经与 Anaconda 一起安装,但我得到一个 ImportError(DLL 加载失败:找不到指定的模块)

© www.soinside.com 2019 - 2024. All rights reserved.