【问题标题】:404 Error on Angular Scripts Deployed to IIS部署到 IIS 的 Angular 脚本出现 404 错误
【发布时间】:2019-11-12 19:37:47
【问题描述】:

我已在 Windows Server 上将 Angular 应用程序部署到 IIS,但由于脚本/样式包都给出 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)

【问题讨论】:

  • 所以实际文件位于http://wavemaker.webdevelopwolf.com/portal/inline.bundle.js?
  • 我的应用程序指向了包含捆绑包的文件夹

标签: angular iis


【解决方案1】:

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

ng b --deploy-url /portal/

【讨论】:

    【解决方案2】:

    建筑用

      ng build --base-href "/portal/" --prod 
    

    确保使用资产文件夹中的图像并在您的 HTML 中像这样引用

     <img src="assets/img.jpg" alt=""> instead of <img src="../../assets/img.jpg" alt="">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-29
      • 2015-01-21
      • 1970-01-01
      • 2018-11-05
      相关资源
      最近更新 更多