angular - 在 Azure 中部署 Angular 应用程序,但刷新时出现 URL 重写模块错误

标签 angular azure azure-web-app-service url-rewrite-module azure-deployment

我们在 azure 中部署了 Angular 应用程序,但刷新应用程序时出现故障,我们收到错误,即“由于发生内部服务器错误,无法显示页面。”

enter image description here

enter image description here

这是我的 Angular 应用程序中的 web.config 文件

<?xml version="1.0"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="Angular Routing" 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>
  <httpProtocol>
    <customHeaders>
      <add name="X-Content-Type-Options" value="nosniff" />
    </customHeaders>
  </httpProtocol>
    <staticContent>
        <mimeMap fileExtension="woff" mimeType="application/font-woff" />
        <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
        <mimeMap fileExtension="json" mimeType="application/json" />
    </staticContent>
</system.webServer>
<system.web>
  <httpCookies httpOnlyCookies="true" requireSSL="true" />
</system.web>
</configuration>

请帮我解决这个问题。

最佳答案

The page cannot be displayed because an internal server error has occurred.

  • 出现此问题的原因是服务器无法访问所请求位置的已配置根目录。

    • 确保服务器可以访问所请求位置的已配置根目录。
  • 看起来还有另一个 web.config 与 dist 和 amd 中的父级配置冲突。

  • 如果启用了详细错误,500 错误必须找到有问题的 web.config 文件。 在 web.config 中,

<configuration>
    <system.web>
        <customErrors mode="Off"/>
        <compilation debug="true"/>
    </system.web>
</configuration>
  • 当使用 Angular 应用程序构建时
ng build --prod

将部署两个 web.config 文件。一个位于根文件夹中,另一个位于 Assets 文件夹中。

  • 检查您的 angular.json 文件 如果您发现类似下面的内容
 "src/web.config"

删除该行

请引用Ref1 , Ref2Ref3 了解更多信息

关于angular - 在 Azure 中部署 Angular 应用程序,但刷新时出现 URL 重写模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71666915/

相关文章:

Azure B2C 自定义策略 - api.localaccountsignup - 仅自动翻译某些字段

azure - 在Azure应用程序洞察中,数据采样(0%与100%)意味着什么

caching - CacheServiceEmulator.exe > 3GB RAM 使用量?

Azure网站保留IP

asp.net-mvc - Visual Studio 2015 在 Web 部署期间找不到 Azure 云上的现有 Web 应用程序

components - 如何将数据注入(inject)从路由器创建的 Angular2 组件?

typescript - Angular 2服务的异步初始化

asp.net - 在不停机的情况下将 Web 流量从一个 Azure Web 应用程序转移到另一个 Azure Web 应用程序

javascript - 十进制一位输入类型只有数字 Ionic 3 最新版本(3.9.2)我正在使用

javascript - CSS 变量和 Angular 5