# Supported way of adding "IncludeSubdomain" to STS headers

**URL:** <https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114>\
**Category:** Development\
**Created:** [January 9, 2026, 9:47pm UTC](https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114 "2026-01-09T21:47:14Z")\
**Posts on this page:** 8\
**Page:** 1

## AI-generated summary

[tanya_byrne](/t/-/393114/1) seeks a supported method to add `IncludeSubDomains` to STS headers in self-hosted Discourse instances, as their internal scanners require it. Previously, they used `sed` and `replace` commands in `app.yml`, but this stopped working. They tried adding a new `90-hsts.conf` file via hooks, but it resulted in duplicate STS headers. [supermathie](/t/-/393114/2) suggested using `set_header`, but this caused SSL errors and was incorrect since nginx doesn’t support it. [pfaffman](/t/-/393114/6) recommended editing `templates/web.ssl.template.yml` directly, which is the simplest solution, and advised copying the file to avoid git conflicts. [tanya_byrne](/t/-/393114/7) thanks both for their input.

<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:** [January 9, 2026, 9:47pm UTC](https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114/1 "2026-01-09T21:47:14Z")

</div>

Hi all,

for our current self hosted Discourse instances, we need to add “IncludeSubDomains” to our STS headers due to this being an expectation of our internal scanners.

Previously I achieved this by using some sed commands in app.yml in custom commands after build to update `/etc/nginx/conf.d/discourse.conf`to include `'add_header Strict-Transport-Security “max-age=31536000; includeSubDomains” always;`

as well as:

```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

```

This previously worked. However, this has stopped working. I read that creating a new outlet file should allow me to add this using:

```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;

```

However, this ends up in there being two STS headers present (one from the SSL template and one from my new template). Is there a better way of doing this so I don’t end up with two STS headers? I would have thought that nginx would respect the last header added, and ignore the SSL template header which just contains `max-age=31536000; `, so is this a defect? Thanks for any guidance you can provide.

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [January 9, 2026, 10:23pm UTC](https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114/2 "2026-01-09T22:23:09Z")

</div>

> [@tanya\_byrne](#):
>
> `add_header`

Does using `set_header` instead of `add_header` solve the problem?

---

<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:** [January 9, 2026, 10:26pm UTC](https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114/3 "2026-01-09T22:26:27Z")

</div>

I’ll give this a go and report back 🙂

---

<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:** [January 9, 2026, 11:52pm UTC](https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114/4 "2026-01-09T23:52:00Z")

</div>

If I use `set_header` I get an SSL error on rebuild, with the cert not being recognized and “connection refused” message when attempting to load the forum page.

Some further information, we use our own SSL cert.

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [January 10, 2026, 12:34am UTC](https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114/5 "2026-01-10T00:34:58Z")

</div>

> [@tanya\_byrne](#):
>
> the cert not being recognized and “connection refused” message

These two errors are mutually exclusive…

Sorry, nginx doesn’t have `set_header` - I misremembered and it’s from another tool.

The easiest option is probably editing `templates/web.ssl.template.yml` with the new values you want.

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [January 10, 2026, 11:55pm UTC](https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114/6 "2026-01-10T23:55:26Z")

</div>

> [@supermathie](#):
>
> The easiest option is probably editing `templates/web.ssl.template.yml` with the new values you want.

I would do that first since it’s easiest. Once you figure it out, the next easiest thing is to copy that file somewhere else so that you don’t have issues with git conflicting with it. The best solution would be to combine your current strategy with another line to remove the other conflicting setting.

---

<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:** [January 11, 2026, 12:07am UTC](https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114/7 "2026-01-11T00:07:28Z")

</div>

Thanks for your help both!

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [February 10, 2026, 12:07am UTC](https://meta.discourse.org/t/supported-way-of-adding-includesubdomain-to-sts-headers/393114/8 "2026-02-10T00:07:40Z")

</div>

Closed on February 10, 2026, 12:07am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
