【问题标题】:Host Angular 7 in Azure web app URL rewrite problem在 Azure Web 应用程序 URL 重写问题中托管 Angular 7
【发布时间】:2023-03-06 00:51:01
【问题描述】:

我在 Azure 中创建了一个 webapp 来托管我的 Angular 7 站点。但是,我有一个问题是网站上没有显示背景图片。

在本地运行良好。

在控制台中,我收到以下错误: 加载资源失败:服务器响应状态为 500(URL 重写模块错误。)

这是我的 web.config 文件:

<configuration>
    <system.webServer>
      <rewrite>
        <rules>
          <rule name="Angular" 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="/" />
          </rule>
        </rules>
      </rewrite>
    </system.webServer>
</configuration>

背景图片位于/assets/images/ 如果我尝试直接转到图像路径,则会收到此错误:

我需要帮助找出背景不显示的原因以及我做错了什么

【问题讨论】:

  • 你把这个放在哪里了?

标签: angular iis azure-web-app-service


【解决方案1】:

我发现了问题。 当使用

构建 Angular 应用程序时
ng build --prod

部署了两个 web.config 文件。 一个在根文件夹中,一个在资产文件夹中。

我发现这样做是因为 angular.json 文件中有这个配置。

解决方案是从配置中删除标记的行:

    "assets": [
      "src/assets",
      "src/favicon.ico",
      "src/web.config" <---- Removed this line
    ],

希望这可以帮助某人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    相关资源
    最近更新 更多