首页 新闻 赞助 找找看

IIS如何启用HSTS以让浏览器默认以https访问

1
悬赏园豆:30 [已解决问题] 解决于 2016-08-17 15:29

请问IIS如何启用HSTS(HTTP Strict Transport Security),让浏览器默认以https访问?

HSTS的效果是这样的:比如在浏览器地址栏输入 q.cnblogs.com (或 http://q.cnblogs.com ),浏览器会自己进行一个307重定向,以 https://q.cnblogs.com 访问,避免向服务器发送http请求。

参考资料:Understanding HTTP Strict Transport Security (HSTS) and preloading it into the browser

dudu的主页 dudu | 高人七级 | 园豆:31075
提问于:2016-08-14 10:35
< >
分享
最佳答案
3

如果https与http绑定在不同的IIS站点上,直接在https站点的web.config中添加如下配置:

<system.webServer>
    <httpProtocol>
        <customHeaders>
            <add name="Strict-Transport-Security" value="max-age=31536000" />
        </customHeaders>
    </httpProtocol>
</system.webServer>

如果在同一个IIS站点,需要针对https响应添加如下的url重写规则(详见How to enable HTTP Strict Transport Security (HSTS) in IIS7+):

<system.webServer>
    <rewrite>
        <outboundRules>
            <rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
                <match serverVariable="RESPONSE_Strict_Transport_Security"
                    pattern=".*" />
                <conditions>
                    <add input="{HTTPS}" pattern="on" ignoreCase="true" />
                </conditions>
                <action type="Rewrite" value="max-age=31536000" />
            </rule>
        </outboundRules>
    </rewrite>
</system.webServer>
dudu | 高人七级 |园豆:31075 | 2016-08-17 15:29
其他回答(2)
0

set http headers:Strict-Transport-Security

收获园豆:30
czd890 | 园豆:14292 (专家六级) | 2016-08-15 13:32

http://www.tuicool.com/articles/iMRjime 看看这个

支持(0) 反对(0) czd890 | 园豆:14292 (专家六级) | 2016-08-15 13:34
0

http应该是存在,你跳到https上面啊,在golbal文件里面处理。

nopcomperce里面就有这样的处理,可以参考。

Supper_litt | 园豆:827 (小虾三级) | 2016-08-16 08:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册