使用掃描網站https://observatory.mozilla.org給我以下錯誤:從 http 到 https 的初始重定向是到不同的主機,從而阻止 HSTS。
問題
- 這是我的設定的真正問題,還是工具中的錯誤,它沒有將子網域視為相同網域的一部分?
- 任何人都可以根據下面的附加資訊建議我可能缺少什麼嗎?
細節
該網站的網域名稱已在 Google Domains 中註冊。為了確保透過以下方式造訪該網站的任何人example.com
都會自動重定向到www.example.com
我已經使用以下規則設定了子網域轉送:
example.com → https://www.example.com
Permanent redirect (301), Forward path
此外,我在 (asp.net) 網站中有規則web.config
將任何 HTTP 連線重新導向到 HTTPS,並新增Strict-Transport-Security
HTTP 標頭(僅透過 HTTPS 呈現時,根據著名的斯科特·漢塞爾曼博客的建議):
<?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=63072000; includeSubDomains; preload" />
</rule>
</outboundRules>
</rewrite>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
<!-- add name="Strict-Transport-Security" value="max-age=63072000; includeSubDomains; preload" / -->
<add name="Content-Security-Policy" value="default-src 'self';" />
<add name="X-Content-Type-Options" value="nosniff" />
<add name="X-Frame-Options" value="DENY" />
<add name="X-Xss-Protection" value="1; mode=block" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
網站本身託管在 Azure 中(在我的 Visual Studio 訂閱免費積分下)。這裡網站的 URL 是example.azurewebsites.net
,在 Google Domains 中我有一個 CName 指向www
(example.azurewebsites.net
在自訂資源記錄下)。