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

Angular 19无SSR应用部署至Windows IIS失败求助

Angular 19非SSR应用IIS部署排查与修复方案

核心排查步骤与配置修改

1. 确认部署文件路径

从你提供的dist目录结构来看,Angular 19的构建产物实际在dist/你的项目名/browser目录下。必须将browser文件夹内的所有文件直接复制到IIS应用的根目录,不能将外层的dist或项目名目录作为部署根目录,否则会导致资源路径错误。

2. 修正web.config配置(关键)

替换你现有的web.config为以下内容,解决路由重写和静态资源MIME类型问题:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <!-- 重写所有非文件/目录请求到index.html,支持Angular路由 -->
        <rule name="Angular Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
        </rule>
      </rules>
    </rewrite>
    <!-- 添加Angular静态资源所需的MIME类型 -->
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <mimeMap fileExtension=".woff" mimeType="font/woff" />
      <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
      <mimeMap fileExtension=".ttf" mimeType="font/ttf" />
      <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
      <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
    </staticContent>
  </system.webServer>
</configuration>
  • 若你的IIS应用部署在子目录(如http://localhost/my-app),需将<action>标签的url值改为"/my-app/index.html",匹配实际子路径。

3. 配置Angular的base href

  • 打开angular.json,找到projects -> 你的项目名 -> architect -> build -> options,确认baseHref配置:
    • 根目录部署:"baseHref": "/"
    • 子目录部署:"baseHref": "/my-app/"
  • 也可在构建时直接指定:ng build --configuration production --base-href="/my-app/"

4. 验证IIS依赖组件

  • 确保IIS已安装URL重写模块,若未安装,可通过Windows服务器管理器的「角色和功能」添加,或从官方渠道获取安装包。

5. 检查应用程序池设置

  • 将应用程序池的.NET CLR版本设置为无托管代码,因为Angular是纯静态前端应用,无需.NET运行时支持。
  • 确认应用程序池的运行身份具有部署目录的读取权限。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 22:28:26