# Enable HSTS with docker

**URL:** <https://community.traefik.io/t/enable-hsts-with-docker/29469>\
**Category:** Traefik\
**Tags:** docker\
**Created:** [December 17, 2025, 5:35pm UTC](https://community.traefik.io/t/enable-hsts-with-docker/29469 "2025-12-17T17:35:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fleodux](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@fleodux](https://community.traefik.io/u/fleodux)\
**Post date:** [December 17, 2025, 5:35pm UTC](https://community.traefik.io/t/enable-hsts-with-docker/29469/1 "2025-12-17T17:35:34Z")

</div>

Hello,

I’m pretty new to traefik (and reverse proxies in general).

I’m using version 3.6 and I’m trying to enable HSTS on my website (self hosted on docker). From what I see traefik configuration is good.

Got the right labels in my docker compose file

> labels:
> 
> - traefik.enable=true
> - traefik.docker.network=traefik\_proxy
> - traefik.http.routers.mysite-https.rule=Host(`mysite.domain.com`)
> - traefik.http.routers.mysite-https.entrypoints=websecure
> - traefik.http.routers.mysite-https.tls=true
> - traefik.http.routers.mysite-https.tls.certresolver=ovhcloud
> - traefik.http.middlewares.mysiteHeader.headers.stsSeconds=15552000
> - traefik.http.middlewares.mysiteHeader.headers.stsIncludeSubdomains=true
> - traefik.http.middlewares.mysiteHeader.headers.stsPreload=true
> - traefik.http.middlewares.mysiteHeader.headers.forceSTSHeader=true

I can see in the dashboard that configuration is applied:

 ![Capture d'écran 2025-12-17 101211](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/1/1d83884e0901db1878e1d6bf8d3c0c6c63ee5233.png)

But when I go to ssllabs to test my url, it tells me HSTS is not enabled:

![Capture d'écran 2025-12-17 101450](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/7/72ff60728f40c88dcd8925eaa643b13f78390fee.png)

Can you help me to find what I’m missing here ?

Thanks

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [December 17, 2025, 6:04pm UTC](https://community.traefik.io/t/enable-hsts-with-docker/29469/2 "2025-12-17T18:04:17Z")

</div>

You declared the `middlewares` ([doc](https://doc.traefik.io/traefik/v3.4/reference/routing-configuration/http/middlewares/headers/#using-security-headers)), but you also need to assign it to the `router`:

```auto
- traefik.http.routers.mysite-https.middlewares=mysiteHeader

```

---

<div class="post-metadata">

**Author:** ![fleodux](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@fleodux](https://community.traefik.io/u/fleodux)\
**Post date:** [December 17, 2025, 7:47pm UTC](https://community.traefik.io/t/enable-hsts-with-docker/29469/3 "2025-12-17T19:47:01Z")

</div>

Thank you for your answer. HSTS is working now

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [December 20, 2025, 7:47pm UTC](https://community.traefik.io/t/enable-hsts-with-docker/29469/4 "2025-12-20T19:47:17Z")

</div>

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