【发布时间】:2020-08-16 19:02:24
【问题描述】:
我有一个特殊情况: 在同一个 IIS 上有网站:
-
sub.domain.com - 它在 80 上有 http,在 443 上有 https。它非常适合您从 http 到 https 的重定向方式
<configuration> <system.webServer> <rewrite> <rules> <rule name="HTTPS force" enabled="true" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration> -
http://sub.domain.com:5000 和 https//sub.domain.com:5001。那个只是拒绝从http传递到https到正确的端口。它可以从http://sub.domain.com:5000 指向https://sub.domain.com:5000 而不是https://sub.domain.com:5001。除非我们清除浏览数据,否则它只能从http://sub.domain.com:5000 到https://sub.domain.com:5001 工作一次。规则喜欢
<rule name="HTTP to HTTPS on different SSL Port" enabled="true" stopProcessing="true"> <match url="(.*)" ignoreCase="true" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="true"> <add input="{HTTPS}" pattern="off" /> <add input="{HTTP_HOST}" pattern="([^/:]*?):[^/]*?" /> </conditions> <action type="Redirect" url="https://{C:1}:5001/{R:0}" appendQueryString="false" /> </rule>
所以我的问题是如何在不清除浏览数据等的情况下成功地将http://sub.domain.com:5000 重定向到https://sub.domain.com:5001?
更新:
在我记录失败的请求日志后,我发现了一些东西。
我在FailedReqLogFiles\W3SVC4 中有 18 个文件。它们每个都有不同的 requestURL。
- 第一个是
http://somedomain.com:5000/,状态码301; - 第二个是
https://somedomain.com:5001/,状态码200。 - 第三个是
https://somedomain.com:5001/inline.e576fger98965b3219.bundle.js,状态码200。 - 第四个是
https://somedomain.com:5001/polyfills.3bed24531fd9085545fdw.bundle.js,状态码200。 - 等等……
- 最后一位(第 18 位)是
https://somedomain.com:5001/assets/images/action,jpg。
如果我查看请求详细信息选项卡中的 GENERAL_ENDPOINT_INFORMATION 节点。它在每个日志文件中都显示Failed To Complete。
重要提示:
这是 .net 核心加 Angular 应用程序。我不确定我应该在角度侧而不是 IIS 或两侧配置 ssl 和重定向 https?
【问题讨论】:
-
你有
Strict-Transport-Securityhttp响应头吗?是的,然后它可以解释为什么它在缓存清除后一次起作用。 en.wikipedia.org/wiki/HTTP_Strict_Transport_Security -
@StanislavBerkov,我有。
Strict-Transport-Security: max-age=2592000 -
但是在角码http头设置中,我没有这个。我应该在Angular中添加它吗?
-
我是说 Strict-Transport-Security 可能是问题的根本原因。尝试删除它。
-
@StanislavBerkov,我不知道如何删除它。在 IIS 中,我不会将它添加到响应标头中。响应头只包含
X-Powered-By: ASP.NET。
标签: angular redirect .net-core https iis-8.5