# 添加 "IncludeSubdomain" 到 STS 标头的受支持方式

**URL:** https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114
**Category:** Development
**Created:** [2026年一月9日 21:47 UTC](https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114 "2026-01-09T21:47:14Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![tanya\_byrne](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tanya_byrne/32/444826_2.png) [@tanya\_byrne](https://meta.discourse.org/u/tanya_byrne)
#### Post date: [2026年一月9日 21:47 UTC](https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114/1 "2026-01-09T21:47:14Z")

</div>

大家好，

对于我们当前的自托管 Discourse 实例，我们需要在 STS 标头中添加“IncludeSubDomains”，因为这是我们内部扫描仪的要求。

以前，我通过在构建后的 `app.yml` 的自定义命令中使用 `sed` 命令来实现此目的，以更新 `/etc/nginx/conf.d/discourse.conf` 以包含 `'add_header Strict-Transport-Security “max-age=31536000; includeSubDomains” always;`

以及：

```plaintext
 - replace:
      filename: "/etc/nginx/conf.d/outlets/discourse/20-https.conf"
      from: /add_header Strict-Transport-Security.+/
      to: add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
      global: true

  - replace:
      filename: "/etc/nginx/conf.d/outlets/server/20-https.conf"
      from: /add_header Strict-Transport-Security.+/
      to: add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
      global: true

```

这以前是有效的。但是，它现在停止工作了。我读到创建一个新的 outlet 文件应该允许我使用以下方法添加此内容：

```plaintext
hooks:
  after_code:
    - file:
        path: /etc/nginx/conf.d/outlets/server/90-hsts.conf
        chmod: 444
        contents: |
          add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

```

然而，这导致存在两个 STS 标头（一个来自 SSL 模板，一个来自我的新模板）。是否有更好的方法可以避免出现两个 STS 标头？我原以为 nginx 会尊重最后添加的标头，并忽略仅包含 `max-age=31536000; ` 的 SSL 模板标头，所以这是个缺陷吗？感谢您提供的任何指导。

---

_[View the full topic](https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114)._
