首页 > 解决方案 > 部署到 IIS 的 Angular 脚本出现 404 错误

问题描述

我已经在 Windows Server 上向 IIS 部署了一个 Angular 应用程序,但由于脚本/样式包都给出 404 错误,它无法加载。我在 IIS 中将我的应用程序设置为“门户”,并在 web.config 中完成了 URL 重写:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
<rewrite>
  <rules>
    <rule name="AngularJS Routes" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
      </conditions>
      <action type="Rewrite" url="/portal" />
    </rule>
  </rules>
</rewrite>
  </system.webServer>
</configuration>

并将 index.html 上的基本 url 设置为:

<base href="/portal">

当我将应用程序构建到 dist 文件夹时,我使用的命令只是一个简单的构建ng b,没有任何选项。

我在控制台中遇到的错误示例是:

GET http://wavemaker.webdevelopwolf.com/inline.bundle.js net::ERR_ABORTED 404 (Not Found)

标签: angulariis

解决方案


要构建应用程序,请使用命令

ng b --deploy-url /portal/

推荐阅读