You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在IIS 10中使用HttpPlatform Handler部署多个Flask应用启动失败问题

问题描述

在IIS的Default Web Site下部署多个结构相似的Python Flask应用时,仅第一个创建的应用可正常运行,后续应用均无法启动。回收对应应用池时,事件查看器中出现HttpPlatformHandler 1000号错误,提示进程启动失败,错误码为-2147023436。

事件日志详情

Log Name:      Application
Source:        HttpPlatformHandler
Date:          10/27/2023 3:46:44 PM
Event ID:      1000
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      
Description:
The description for Event ID 1000 from source HttpPlatformHandler cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event: 

Process '10260' failed to start. Port = 20173, Error Code = '-2147023436'.

Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="HttpPlatformHandler" />
    <EventID Qualifiers="0">1000</EventID>
    <Level>2</Level>
    <Task>0</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2023-10-27T10:16:44.326060800Z" />
    <EventRecordID>1926695</EventRecordID>
    <Channel>Application</Channel>
    <Computer>BAVNAPPCNV01.PEARL.COM</Computer>
    <Security />
  </System>
  <EventData>
    <Data>Process '10260' failed to start. Port = 20173, Error Code = '-2147023436'.</Data>
  </EventData>
</Event>

当前web.config配置

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpPlatform processPath="D:\Program Files (x86)\Utilities\report\report\env\Scripts\python.exe" arguments="-m flask run --port 4001">
            <environmentVariables>
                <environmentVariable name="FLASK_APP" value="report.py" />
            </environmentVariables>
        </httpPlatform>
        <handlers>
            <add name="reportHttpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" scriptProcessor="D:\Program Files (x86)\Utilities\report\report\env\Scripts\python.exe" resourceType="Unspecified" />
        </handlers>
    </system.webServer>
</configuration>

解决方法

1. 移除硬编码端口,使用HttpPlatform自动分配端口

错误码-2147023436对应Windows系统错误0x8007058A,核心原因是多个应用尝试绑定同一个硬编码端口(如配置中的4001)导致冲突。修改web.config中的arguments,让Flask使用HttpPlatformHandler自动分配的端口:

<httpPlatform processPath="D:\Program Files (x86)\Utilities\report\report\env\Scripts\python.exe" arguments="-m flask run --port %HTTP_PLATFORM_PORT%">

2. 为每个应用配置独立应用池

  • 每个Flask应用创建单独的应用池,避免进程资源冲突
  • 将应用池的.NET CLR版本设置为无托管代码,Python应用不需要.NET运行时支持

3. 验证应用目录与虚拟环境权限

  • 确保应用池标识(如IIS AppPool\你的应用池名称)对Flask应用目录、Python虚拟环境目录拥有读取、执行权限
  • 手动在应用目录下启动虚拟环境的Python,执行flask run命令,确认应用本身可正常启动,排除代码或依赖问题

4. 清理残留进程

打开任务管理器,结束所有残留的python.exe进程,再重新启动IIS应用池,避免旧进程占用资源

内容的提问来源于stack exchange,提问作者chongtham pankaj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 04:52:42