IIS 配置 HTTP 自动跳转到 HTTPS

To enable HTTP Strict Transport Security (HSTS) in IIS, need to add the appropriate headers to your web server's configuration:

  1. Open IIS Manager: Start by opening the Internet Information Services (IIS) Manager.
  2. Select Your Site: In the Connections pane, expand the node for your server, and then expand the Sites node. Select the site you want to configure.
  3. Open HTTP Response Headers: In the Features View, double-click on the "HTTP Response Headers" feature.
  4. Add HSTS Header: In the Actions pane on the right, click on "Add..." to add a new HTTP response header. Use the following settings:
  • Name: Strict-Transport-Security
  • Value: max-age=31536000; includeSubDomains
    
    This configuration sets the HSTS policy to a max age of one year and includes all subdomains.
    Here's a sample configuration code for adding the HSTS header using the web.config file:
<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

This code should be placed within the <configuration> section of your web.config file.

5. Restart IIS

posted @ 2024-12-17 14:23  Robot-Blog  阅读(209)  评论(0)    收藏  举报