【问题标题】:Site can't be reached error-After hosting Angular app on IIS 8.0无法访问站点错误-在 IIS 8.0 上托管 Angular 应用程序后
【发布时间】:2021-02-21 01:57:24
【问题描述】:

最近我在我们的测试服务器(IIS 8.0)上托管了一个 Angular(版本 10)网络应用程序。并且还在 IIS 中安装了URL Rewrite Module

以下是我为规则添加的 web.config。

<configuration>
<system.webServer>
  <rewrite>
    <rules>
      <rule name="Redirect all requests" 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="./index.html" />
        </rule>
    </rules>
  </rewrite>
  <directoryBrowse enabled="true" />
  <httpErrors errorMode="Custom">
      <remove statusCode="404"/>
      <error statusCode="404" path="/index.html" responseMode="ExecuteURL"/>
  </httpErrors>
</system.webServer>
<system.web>
    <customErrors mode="On" redirectMode="ResponseRewrite">
      <error statusCode="404" redirect="/index.html" />
    </customErrors>
    </system.web>
</configuration>

但在托管应用程序后,网站正在运行,但不断出现以下错误无法访问网站,如下面的屏幕截图所示。出现错误后,URL 会在几秒钟内自动重新加载,然后网站按预期工作。

以下是我的应用程序池设置。

这个错误的原因是什么?它也在没有空闲时间的情况下发生。我是否缺少任何 IIS 设置?还是需要添加任何其他 URL 编写规则?或者任何设置需要包含在我的角度应用程序中?请帮帮我。

[更新]

借助调试工具发现错误出在angular配置文件中。

【问题讨论】:

标签: angular iis url-rewriting web-hosting angular-components


【解决方案1】:

经过一番搜索并在调试工具的帮助下终于能够修复错误。用 ngsw-config.json

中的应用程序路径更改了 index 属性
"index": "YourAppPath/index.html"

解决了这个问题。更多详细信息请通过角度文档here

错误详情请到question

【讨论】:

    【解决方案2】:

    需要做两件事:
    首先你需要从https://www.iis.net/downloads/microsoft/url-rewrite下载安装url rewrite

    那么您需要更改您的 web.config 文件以重定向到 index.html 文件以使用 Angular 2 路由

    这是您可以使用的web.config 文件

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

    没有其他要求。我的网站也在使用上述相同的方式 我的网站也在 angular 10 Ivy

    还有一件重要的事情是,只需将您的站点主文件夹权限授予所有人。由于权限站点无法访问,许多开发人员都会发生这种情况

    【讨论】:

    • 我已经安装了 url 重写模块,甚至尝试使用上面的 web.config 但结果相同,并且对于站点文件夹,我在应用程序池中使用了管理员帐户
    猜你喜欢
    • 1970-01-01
    • 2015-03-23
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多