HSTS (HTTP Strict Transport Security) 是一种安全策略,强制浏览器使用HTTPS连接。以下是确定HSTS状态的方法:
Chrome/Edge浏览器:
1. 访问 chrome://net-internals/#hsts
2. 在"Query HSTS/PKP domain"输入域名查询
3. 结果会显示该域名是否在HSTS列表中及其过期时间
Firefox浏览器:
1. 访问 about:config
2. 搜索 security.mixed_content.use_hsts_cache
3. 确认其为true表示HSTS功能启用
网站是否发送了HSTS头可以通过检查HTTP响应头:
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
使用curl检查:
curl -I https://example.com | grep Strict-Transport-Security
当HSTS导致HTTP请求无法跳转时,可以尝试以下解决方法:
清除浏览器HSTS设置:
- Chrome/Edge: 在 chrome://net-internals/#hsts
页面底部"Delete domain"输入域名并删除
- Firefox: 清除浏览器历史记录(包括"活动日志")
使用隐私/无痕模式: - HSTS设置在隐私模式下通常不会生效
修改hosts文件: - 临时使用IP地址访问(不推荐长期使用)
正确配置服务器: 1. 确保所有HTTP请求重定向到HTTPS(在HSTS头生效前)
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
逐步部署HSTS: - 初始阶段使用较短的max-age值(如300秒) - 确认无误后逐步增加
从HSTS预加载列表中移除: 1. 访问 https://hstspreload.org/ 2. 提交移除请求(需等待浏览器更新)
使用不同域名: - 临时使用未启用HSTS的备用域名
使用HTTP代理: - 通过代理服务器访问(不推荐,可能影响安全性)
preload
指令前充分测试HSTS是重要的安全功能,但需要谨慎部署以避免访问问题。正确配置后能有效提升网站安全性。