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

如何将Python可执行文件部署至Azure App Service并实现域名访问?

解决Windows Azure App Service部署Flask打包.exe的域名访问问题

核心问题

Azure App Service Windows环境默认对外暴露80/443端口,你的.exe当前仅监听8000端口,且缺少IIS与.exe之间的路由配置,导致域名请求无法转发到8000端口。

具体配置步骤

1. 确认exe的监听配置

确保你的Flask应用(打包前的代码)启动时监听0.0.0.0和8000端口,保证能接收外部请求:

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)

若已打包成exe且代码未做此配置,需重新打包。

2. 创建web.config文件(关键)

在/site/wwwroot目录下创建web.config文件,用于配置IIS转发请求到你的exe:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath=".\你的应用文件名.exe" arguments="" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" startupTimeLimit="30">
      <environmentVariables>
        <environmentVariable name="PORT" value="8000" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>
  • 将你的应用文件名.exe替换为实际的exe文件名
  • 开启stdoutLogEnabled可在/site/wwwroot/logs目录查看运行日志,方便排查问题

3. 配置启动命令(备选)

若web.config未生效,进入Azure Portal的App Service管理页:

  • 进入「配置」>「通用设置」
  • 在「启动命令」中填入:.\你的应用文件名.exe
  • 保存后重启App Service

4. 排查验证

  • 确认exe未硬编码监听127.0.0.1,必须是0.0.0.0才能接收外部请求
  • 查看App Service的「日志流」或/site/wwwroot/logs/stdout文件,排查启动失败或请求转发异常的原因

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 17:19:54