IIS服务器配置HSTS

发布时间:2019/11/9 16:27:02 打印 字号:

确认是否安装 “URL 重写” 或者 “URL Rewrite” 模块 , 如果您已经安装可以跳过

“URL重写” 模块下载地址

微软下载地址(64位):http://www.microsoft.com/zh-cn/download/details.aspx?id=7435
微软下载地址(32位):http://www.microsoft.com/zh-cn/download/details.aspx?id=5747

第一步: 选择站点,  “URL 重写”,如果安装的是英文版的 应该是【Url Rewrite】

第二步: 添加 “ 空白规则”

QQ截图20191109162930.png

560025-20190120041926243-766443414.png

第三步:添加规则

名称 : HTTP响应
匹配范围:服务器变量

变量名称:RESPONSE_Strict_Transport_Security

模式:.*

560025-20190120041935163-545067760.png


条件输入:HTTPS

模式:on

560025-20190120041943002-462925472.png

值:max-age=31536000


高级配置,网站根目录创建:web.config文件夹,具体代码:

<?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="HTTP to HTTPS redirect" stopProcessing="true">
              <match url="(.*)" />
              <conditions>
                <add input="{HTTPS}" pattern="off" ignoreCase="true" />
              </conditions>
              <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
             </rule>
           </rules>
           <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; includeSubDomains; preload" />
             </rule>
           </outboundRules>
         </rewrite>
       </system.webServer>
     </configuration>