# www和非www设置未设置HSTS标头

**URL:** <https://meta.discourse.org/t/hsts-header-not-set-with-www-and-non-www-setup/241104>\
**Category:** Product Support\
**Tags:** nginx\
**Created:** [2022 年10 月 6 日 08:23 UTC](https://meta.discourse.org/t/hsts-header-not-set-with-www-and-non-www-setup/241104 "2022-10-06T08:23:24Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![OrkoGrayskull](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/orkograyskull/32/275883_2.png) [@OrkoGrayskull](https://meta.discourse.org/u/OrkoGrayskull)\
发布日期： [2022 年10 月 6 日 08:23 UTC](https://meta.discourse.org/t/hsts-header-not-set-with-www-and-non-www-setup/241104/1 "2022-10-06T08:23:24Z")

</div>

你好，

我正在使用标准安装。

这是我在 app.yml 中修改的内容：

```plaintext
hooks:   
## 为非 www 和 www 域名添加 Let's Encrypt 证书   
  after_ssl:     
    - replace:         
        filename: "/etc/runit/1.d/letsencrypt"         
        from: /--keylength/         
        to: "-d example.com -d www.example.com --keylength"

```

你的 Discourse 的主机名是：`www.example.com`

到目前为止，设置工作正常，并且证书已为 `example.com` 和 `www.example.com` 提供。

但是，当我使用 SSLLabs 检查 SSL 参数时，`www.example.com` 域缺少 HSTS 标头。对于 `example.com`，它是有效的：

> 严格传输安全 (HSTS) **是**  
> max-age=31536000; includeSubdomains; preload

而 Hardenize ([www.hardenize.com](http://www.hardenize.com)) 的说法如下：

> 从 HTTP 重定向到 HTTPS 而不是同一个主机
> 
> 当使用 HSTS 时，明文端口应重定向到同一主机的 HTTPS 变体。此方法可确保在该主机名上启用 HSTS，即使以后客户端被发送到其他地方。重定向到另一个主机仅在它是已启用 includeSubDomains 的父主机时才是安全的，但这里不是这种情况。
> 
> **起点：** `http://example.de`
> 
> **当前重定向：** `https://www.example.com`
> 
> **预期重定向：** `https://example.com`

> 策略未预加载
> 
> 当主机名被预加载时，意味着浏览器会嵌入你的 HSTS 策略，即使是发送到你网站的第一个请求也会应用该策略。此服务器在其策略中指示预加载，但域名实际上并未预加载。我们将此归类为警告，因为将“preload”关键字放在策略中，而基础结构尚未准备好进行预加载，这是一个常见问题。这很危险，因为在这种情况下，任何人都可以通过访问 `hstspreload.org` 来提交此域名进行预加载。我们建议你自行预加载此域名（如果已准备好），或者在基础结构准备好之前从策略中删除预加载指示符。

关于为什么 HSTS 标头 **未** 为 **[www.example.com](http://www.example.com)** 域设置，有什么想法吗？

---

_[View the full topic](https://meta.discourse.org/t/hsts-header-not-set-with-www-and-non-www-setup/241104)._
