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

Angular v17无SSR项目部署IIS服务器失败求助

Angular 17 无SSR项目部署到IIS子目录的正确步骤

一、项目构建

执行带基础路径参数的构建命令,确保资源加载路径正确:

ng build --base-href "/angular-project/" --configuration production
  • 构建完成后,将dist/AppName/browser下的所有文件复制到服务器的wwwroot/angular-project目录中
  • 确认web.config已添加到angular.json的assets数组中,确保构建时会同步复制到browser目录

二、修正URL重写配置(web.config)

原配置中路由重写的目标路径未匹配子目录,导致无法正确指向index.html,修正后的配置如下:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <clear />
        <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>
          <!-- 修正为子目录路径,确保重写指向子目录的index.html -->
          <action type="Rewrite" url="/angular-project/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

三、IIS站点配置

  • 打开IIS管理器,创建新站点:
    • 物理路径选择服务器上的wwwroot/angular-project目录
    • 设置站点绑定(端口、主机名等,根据公司服务器规则配置)
  • 必须安装URL Rewrite模块:如果IIS未安装该模块,重写规则无法生效,需从IIS官方扩展库安装

四、验证部署

  1. 访问站点地址:http://{服务器IP}:{端口}/angular-project,确认首页正常加载
  2. 测试路由跳转:直接访问子路由(如http://{服务器IP}:{端口}/angular-project/about),刷新页面后确认不会出现404错误

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 09:34:57