问题描述
-
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。 - 等等....
- 最后一个(18th)是
https://somedomain.com:5001/assets/images/action,jpg
。
如果我在“请求详细信息”选项卡中查看GENERAL_ENDPOINT_@R_791_4045@ION节点。它将在每个日志文件中显示Failed To Complete
。
重要提示:
这是.net核心加上有角度的应用程序。我不确定我应该配置ssl并在有角度的一面而不是在IIS或两面都重定向https吗?
解决方法
您可以尝试以下规则:
<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="{SERVER_PORT}" pattern="^2000$" />
<add input="{HTTP_HOST}" pattern="([^/:]*?):[^/]*?" />
</conditions>
<action type="Redirect" url="https://{C:1}:2001/{R:1}" appendQueryString="false" />
</rule>
注意:根据您的站点绑定和要求以一种模式设置端口号。
另外,尝试设置iis客户端缓存设置。
https://docs.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/clientcache
,经过几天的挣扎。终于找到了解决方法。
我必须做两件事。
-
在IIS上应用规则
<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" />
-
从.net核心代码中删除HSTS。我有代码
public void Configure(IApplicationBuilder app,IHostingEnvironment env) { app.UseHsts();
将其删除即可。感谢@StanislavBerkov