IIS 允许路由到虚拟目录
IIS allowing routing to virtual dir
我正在尝试在 Azure 上的同一个 Web 应用程序中托管我的 angular 应用程序和 api。
但我在访问 api.
时遇到了一些困难
文件夹结构如下:
├───api
│ └───bin
│ └───web.config <== API web.config
├───index.html
├───web.config <== Angular web.config
├───...
└───assets
├───flags
├───i18n
├───icons
└───images
所以我需要告诉我的 Angular web.config
将所有 /api
呼叫重定向到 api。同时仍然将所有其他调用还原到根文件夹
中的 index.html
但我似乎不太对劲,这是我现在的 web.config。但这会将我的 api 调用重定向到客户端的 index.html.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<remove fileExtension=".ttf" />
<mimeMap fileExtension=".woff" mimeType="font/woff" />
<mimeMap fileExtension=".woff2" mimeType="font/woff2" />
<mimeMap fileExtension=".ttf" mimeType="font/ttf" />
<mimeMap fileExtension=".webmanifest" mimeType="application/manifest+json" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
<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" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="." />
</rule>
</rules>
</rewrite>
<!-- gzip compression -->
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="font/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="application/json" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="font/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
</system.webServer>
<location path="index.html">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
这导致以下清单
- 加载 angular 应用 => TRUE
- 加载文件(favicon,main.js,ngsw-worker.js)=> TRUE
- 加载 manifest.webmanifest => TRUE
- 加载 api => FALSE
有人知道工作的想法吗web.config
?
更新:通过将其添加到静态内容
修复了manifest.webmanifest问题
我在 Azure App Services 中有相同的设置 运行 并且 运行 遇到了试图让一切正常工作的问题。最后,我遇到的问题是我的 SPA 应用程序 web.config 被 API 应用程序继承了。这在尝试调用我的 API 应用程序时导致 405 错误。
我的解决方案是调整 web.config 并关闭继承。
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="AngularJS 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="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</location>
</configuration>
我正在尝试在 Azure 上的同一个 Web 应用程序中托管我的 angular 应用程序和 api。 但我在访问 api.
时遇到了一些困难文件夹结构如下:
├───api
│ └───bin
│ └───web.config <== API web.config
├───index.html
├───web.config <== Angular web.config
├───...
└───assets
├───flags
├───i18n
├───icons
└───images
所以我需要告诉我的 Angular web.config
将所有 /api
呼叫重定向到 api。同时仍然将所有其他调用还原到根文件夹
index.html
但我似乎不太对劲,这是我现在的 web.config。但这会将我的 api 调用重定向到客户端的 index.html.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<remove fileExtension=".ttf" />
<mimeMap fileExtension=".woff" mimeType="font/woff" />
<mimeMap fileExtension=".woff2" mimeType="font/woff2" />
<mimeMap fileExtension=".ttf" mimeType="font/ttf" />
<mimeMap fileExtension=".webmanifest" mimeType="application/manifest+json" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
<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" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="." />
</rule>
</rules>
</rewrite>
<!-- gzip compression -->
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="font/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="application/json" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="font/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
</system.webServer>
<location path="index.html">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
这导致以下清单
- 加载 angular 应用 => TRUE
- 加载文件(favicon,main.js,ngsw-worker.js)=> TRUE
- 加载 manifest.webmanifest => TRUE
- 加载 api => FALSE
有人知道工作的想法吗web.config
?
更新:通过将其添加到静态内容
修复了manifest.webmanifest问题我在 Azure App Services 中有相同的设置 运行 并且 运行 遇到了试图让一切正常工作的问题。最后,我遇到的问题是我的 SPA 应用程序 web.config 被 API 应用程序继承了。这在尝试调用我的 API 应用程序时导致 405 错误。
我的解决方案是调整 web.config 并关闭继承。
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="AngularJS 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="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</location>
</configuration>