ページ更新日:2026/06/11
IIS(Internet Information Services)で HSTS(HTTP Strict Transport Security) を設定する方法を解説します。
IISのバージョンによって推奨される設定方法が異なります。IIS 10.0 バージョン1709(Windows Server 2016 バージョン1709 / Windows Server 2019以降)ではネイティブのHSTS機能が利用でき、それより前のバージョンでは web.config のカスタムヘッダーまたは URL Rewrite で設定します。
IIS 10.0 バージョン1709以降では、サイト単位の <hsts> 要素でHSTSを設定できます。
HTTPSレスポンスにのみヘッダーを付与し、HTTP→HTTPSリダイレクトも同時に設定できるため、後述の web.config 方式の問題(HTTPレスポンスにもヘッダーが付く)が発生しません。
%windir%\System32\inetsrv\config\applicationHost.config の対象サイトの <site> 要素内に <hsts> を追加します。
<site name="Default Web Site" id="1">
<application path="/">
<virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:" />
<binding protocol="https" bindingInformation="*:443:" sslFlags="0" />
</bindings>
<hsts enabled="true" max-age="31536000" includeSubDomains="true" redirectHttpToHttps="true" />
</site>
enabled="true":HSTSを有効化max-age="31536000":ブラウザがHTTPS強制を記憶する秒数(31536000秒=1年)includeSubDomains="true":サブドメインにも適用(全サブドメインがHTTPS対応済みの場合のみ)redirectHttpToHttps="true":HTTPアクセスをHTTPSへ301リダイレクトpreload="true":HSTSプリロードリスト 申請用(登録解除が困難なため慎重に)Import-Module IISAdministration
Start-IISCommitDelay
$sites = Get-IISConfigSection -SectionPath "system.applicationHost/sites" | Get-IISConfigCollection
$site = Get-IISConfigCollectionElement -ConfigCollection $sites -ConfigAttribute @{"name"="Default Web Site"}
$hsts = Get-IISConfigElement -ConfigElement $site -ChildElementName "hsts"
Set-IISConfigAttributeValue -ConfigElement $hsts -AttributeName "enabled" -AttributeValue $true
Set-IISConfigAttributeValue -ConfigElement $hsts -AttributeName "max-age" -AttributeValue 31536000
Set-IISConfigAttributeValue -ConfigElement $hsts -AttributeName "includeSubDomains" -AttributeValue $true
Set-IISConfigAttributeValue -ConfigElement $hsts -AttributeName "redirectHttpToHttps" -AttributeValue $true
Stop-IISCommitDelay
IIS 10.0 バージョン1709より前(IIS 7.0〜10.0 初期)では、web.config の <customHeaders> でHSTSヘッダーを追加できます。
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains" />
</customHeaders>
</httpProtocol>
</system.webServer>
注意:この方法では HTTP のレスポンスにも HSTS ヘッダーが付与されます。
RFC 6797 では「HSTSヘッダーはHTTPSレスポンスでのみ送信すべき」と定められています(ブラウザはHTTPレスポンスのHSTSヘッダーを無視するため実害は小さいものの、仕様違反となります)。
HTTPバインドを持つサイトでは、次の URL Rewrite 方式を使うか、方法1のネイティブ機能への移行を推奨します。
URL Rewrite モジュール のアウトバウンドルールを使うと、HTTPSレスポンスにのみHSTSヘッダーを付与できます。HTTP→HTTPSリダイレクトとあわせた設定例です。
<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" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
Strict-Transport-Security、値に max-age=31536000; includeSubDomains を入力して「OK」
※ GUIでの追加は web.config の <customHeaders> に書き込まれるため、HTTPレスポンスにもヘッダーが付く点は同じです。
(Invoke-WebRequest https://www.example.com -UseBasicParsing).Headers["Strict-Transport-Security"]
curl -I https://www.example.com
レスポンスに Strict-Transport-Security: max-age=31536000; ... が含まれていれば設定完了です。
max-age=300(5分)でテストし、問題なければ 2592000(30日)→ 31536000(1年)と延ばします。詳しくは HSTSとは?設定方法と注意点 の「段階的な導入手順」をご参照ください。includeSubDomains を省いてください。<customHeaders> 側の定義を削除してください。hsts 要素)は、HTTPSレスポンスにのみヘッダーを付与し、HTTP→HTTPSリダイレクトも同時に設定できます。web.config の customHeaders 方式は古いIISでも使えますが、HTTPレスポンスにもヘッダーが付与されるため RFC 6797 の仕様に反します(実害は小さいものの非推奨)。IIS 10.0 1709以降ではネイティブ機能の利用を推奨します。
curl -I https://ドメイン名 でヘッダーの有無を確認してください。
📌 関連ページ:
HSTS(HTTP Strict Transport Security)とは?設定方法と注意点
ApacheでHSTS(常時SSL)設定
NginxのHSTSとTLS設定強化(SSL Labs A+ 達成設定例)
IIS(Windows Server)へのSSL証明書インストール手順
opensslでpfxファイルを作成する方法(IISインポート用)
常時SSL(Always On SSL)について