簡體   English   中英

無法訪問站點錯誤 - 在 IIS 8.0 上托管 Angular 應用程序后

[英]Site can't be reached error-After hosting Angular app on IIS 8.0

最近,我在我們的測試服務器 (IIS 8.0) 上托管了一個 angular(版本 10)Web 應用程序。 並且還在 IIS 中安裝了URL 重寫模塊

以下是我為規則添加的 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配置文件中。

有兩件事需要:
首先,您需要通過從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

還有一件重要的事情是,將您的站點主文件夾權限授予所有人。 由於權限站點無法訪問,許多開發人員都會發生這種情況

經過一點點搜索和調試工具的幫助,終於能夠修復錯誤。 使用ngsw-config.json 中的應用程序路徑更改索引屬性

"index": "YourAppPath/index.html"

這解決了這個問題。 更多細節請在此處查看角度文檔

有關錯誤的詳細信息,請查看此問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM