在 IIS 中配置站点支持 HSTS
详见文档:https://learn.microsoft.com/zh-cn/iis/get-started/whats-new-in-iis-10-version-1709/iis-10-version-1709-hsts
简单的说在 1709 版本之前的 IIS 中
最方便的就是安装 URL 重写模块(下载:https://iis-umbraco.azurewebsites.net/downloads/microsoft/url-rewrite)
再到网站的 web.config 中添加以下配置:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Redirect HTTP to HTTPS" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> </rule> </rules> <outboundRules> <rule name="Add the STS header in HTTPS responses"> <match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" /> <conditions> <add input="{HTTPS}" pattern="on" /> </conditions> <action type="Rewrite" value="max-age=31536000" /> </rule> </outboundRules> </rewrite> </system.webServer> </configuration>
1709 之后,可直接在 IIS 中网站上点击右键》管理网站》高级设置,在弹窗的对话框中即可找到 HSTS 配置:
将“已启用”改为“True”,“Max-Age”设为“31536000”
检测配置是否生效:
https://www.ssleye.com/ssltool/hsts_check.html
http://web.chacuo.net/nethstscheck
输了你,赢了世界又如何...