在Azure Web应用URL中托管Angular 7 URL重写问题 [英] Host Angular 7 in Azure web app URL rewrite problem

查看:67
本文介绍了在Azure Web应用URL中托管Angular 7 URL重写问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Azure中创建了一个Web应用程序来托管我的Angular 7网站.但是我有一个问题,背景图片没有显示在网站上.

I have created a webapp in Azure to host my Angular 7 site. However I have a problem with the background image not being shown on the site.

在本地工作正常.

在控制台中,出现以下错误: 无法加载资源:服务器的状态为500(URL重写模块错误).

In the console I get the following error: Failed to load resource: the server responded with a status of 500 (URL Rewrite Module Error.)

这是我的web.config文件:

This is my web.config file:

<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/ 如果我尝试直接转到图像路径,则会出现此错误:

The background image is located in /assets/images/ If I try to go directly to the image path I get this error:

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

I need help to find out why the background doesn't show and what I have done wrong

推荐答案

我发现了问题. 使用

ng build --prod

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

Two web.config files where deployed. One in the root folder and one in the assets folder.

我发现完成此操作是因为angular.json文件中包含此配置.

I found that this was done because the angular.json file had this configuration in it.

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

The solution was to remove the marked line form the configuration:

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

希望这可以帮助某人.

这篇关于在Azure Web应用URL中托管Angular 7 URL重写问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆