如何在 IIS 上部署 Angular SSG

问题描述 投票:0回答:1

我有一个 Angular SSG(站点静态生成),我需要部署在 IIS 10 服务器上。 对于每个生成的 html 文件,Angular 创建了一个文件夹 page1.html/index.html,其中 page1 是一个文件夹。 所以不能轻易地提供给IIS。它需要一些 HTTP 处理程序。

angular iis static-site-generation
1个回答
0
投票

您可以尝试使用iis url重写,在Angular SSG构建的根目录中,创建或更新web.config文件,您需要设置重写规则,以便对

/page1.html
的请求路由到
/page1.html/index.html
。下面的ruel可以作为参考:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
      <!-- Redirect all requests for /something.html to /something.html/index.html -->
        <rule name="Static HTML SSG Rewrite" stopProcessing="true">
          <match url="^(.*)\.html$" />
            <conditions>
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
              <add input="{REQUEST_FILENAME}/index.html" matchType="IsFile" />
             </conditions>
         <action type="Rewrite" url="{R:1}.html/index.html" />
      </rule>

      <!-- Handle default fallback to index.html for Angular routes -->
      <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>

    <!-- Optional: Static content compression and caching -->
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
    </staticContent>
  </system.webServer>
</configuration>

此外,如果您要提供某些静态文件,请确保在 IIS 中配置了适当的 MIME 类型。然后将所有生成的文件从 Angular SSG 版本复制到 IIS 站点的根文件夹,重新启动 IIS 或回收应用程序池以应用更改。

© www.soinside.com 2019 - 2024. All rights reserved.