如何在具有多个应用程序的情况下,使用 IIS 部署 Angular 15 应用程序。

huangapple go评论55阅读模式
英文:

How to deploy Angular 15 app with iis that has multiple apps

问题

我已经尝试更改index.html中的基本href

<base href="/AppName/">

我还添加了重定向配置。

<?xml version="1.0" encoding="utf-8"?>
<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>

我已经查看了stackoverflow中的所有问题,但那里有很多与情况相关的无关信息,没有一个对我起作用。我只需要有人告诉我这样做,它会起作用

对我来说很不可思议的是,文档中没有提供这些信息,我们必须在问题和问题之间寻找解决方案。

英文:

I have tried changing the base href in index.html

<base href="/AppName/">

I have also added, the rerouting config.

<?xml version="1.0" encoding="utf-8"?>
<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>

I have gone through all of the questions in stackoverflow but there is a lot of irrelevant, case related info out there, and none of them worked for me. I just need someone to tell me do this and it will work

It is insane to me that this info is not given in the docs, and we have to jump through questions and issues to find the solution.

答案1

得分: 1

要将Angular应用程序部署为IIS应用程序,您可以按照以下步骤进行操作:

1)运行以下命令来构建Angular应用程序:

ng build --base-href='/basepath/'

基本路径将与IIS应用程序名称相同

2)在IIS中创建应用程序,并指向dist目录以及您的Angular构建路径,类似于以下方式:

C:\app-name\dist\app-name

3)在以下路径C:\app-name\dist\app-name创建web.config文件:

<?xml version="1.0" encoding="UTF-8"?>
<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>

注意:不要忘记将iis_iusrs和iusr用户分配权限给站点根文件夹。

英文:

To deploy the angular app in iis as application you can follow beelow steps:

  1. Run below command to build the angular app:

ng build --base-href='/basepath/'

base path will be the same app name as iis application name

  1. Create application in iis and point to the dist and your angular build path something like below:

C:\app-name\dist\app-name

  1. Create web.config file as below at this path C:\app-name\dist\app-name:

    <?xml version="1.0" encoding="UTF-8"?>
    <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>

Note: Do not forgot to assign iis_iusrs and iusr user permission to the site root folder

huangapple
  • 本文由 发表于 2023年2月16日 16:25:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75469533.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定