Running it

Common HSTS Configuration Mistakes and Fixes

Eight HSTS mistakes that leave gaps or lock visitors out, with tested Apache, Nginx and Caddy settings, Cloudflare steps and a safe max-age rollout.

Illustration: a server with a wrench and a cracked shield above three houses, one unlocked

Why HSTS goes wrong

HSTS is a single response header, and most of the ways it goes wrong come from that simplicity. It is easy to add in the wrong place, easy to add in only some places, and easy to add with settings that cannot be taken back quickly. The failures fall into two groups:

  • Gaps: the header is missing where it matters, so visitors are not protected and scanners keep flagging it.
  • Lockouts: the header reaches a host that cannot serve valid HTTPS, and browsers refuse to open it, with no button to continue.

Below are the eight mistakes we see most, how to spot each one, and tested configuration for Apache, Nginx and Caddy, plus Cloudflare's settings quoted from its documentation. If you need the background first, read what HSTS is; for the testing methods used here, see how to test HSTS headers.

1. Sending the header over plain HTTP

The standard requires browsers to ignore Strict-Transport-Security on a plain HTTP response. A header added to the port 80 virtual host, or to the http to https redirect, protects nobody. It is the most common first attempt, because the port 80 block is where people go to set up the redirect.

Spot it: curl -sI http://shop.com shows the header while curl -sI https://shop.com does not.

Fix: move the header into the HTTPS server block. Keeping a copy on port 80 does no harm, but it does nothing either.

2. Only on some paths

A header set for the site can still be missing from parts of it. We reproduced the classic Nginx case in a container running nginx 1.27.5: the header is set at server level, and a location block for static files adds a caching header of its own.

Terminal output from nginx where a stylesheet and a 404 page lack the HSTS header
Reproduced in nginx 1.27.5. A location block with its own add_header loses the server level header, and without always the error page goes out bare.

Two holes in one short file:

  • Inheritance. Nginx inherits add_header directives from the level above only if the current level has none of its own. The moment the /assets/ block added Cache-Control, it silently lost HSTS.
  • Error responses. Without the always parameter, Nginx adds headers only to success and redirect responses. The 404 page went out bare.

Neither hole stops a returning visitor's rule from working, since any response with the header refreshes it. They do matter for scanners, for first visits that land on an asset or an error, and for the preload checks, which look at specific responses. The tested fix is further down.

Spot it: test a page, a stylesheet or image, and a URL that returns 404. Every HTTPS response should carry the header.

3. Only on the www host

The site is www.shop.com, the header is configured there, and the bare shop.com only redirects. The apex never sends the header, so a visitor who types shop.com gets no rule for the apex, and includeSubDomains on www does not cover names above it. Our own site had exactly this gap when we tested it for this series.

Spot it: run the HSTS Checker against https://shop.com and https://www.shop.com separately, or walk every hop with the redirect checker.

Fix: send the header on the HTTPS redirect response from the apex as well. hstspreload.org requires it for preloading: if the base domain redirects, that redirect must itself carry the header.

4. A short max-age that keeps expiring

Someone set max-age=300 to test and never raised it, or a hosting panel shipped a default of a day. Every visitor's rule expires minutes or hours after their last visit, so on their next visit the first request goes out over plain HTTP again. The header is present, scanners may even pass it, and it protects almost nothing.

Spot it: the checker shows max-age in days. Below 180 days is short; one year (31536000) is the usual target and the preload minimum.

Fix: finish the rollout described at the end of this post.

5. includeSubDomains breaking an http-only subdomain

This is the lockout that generates support tickets. includeSubDomains sent from shop.com covers every name below it, and the ones that break are the ones nobody thought of.

Diagram of an apex HSTS rule reaching five subdomains, three of which cannot serve HTTPS
Webmail, staging and office devices are the usual casualties. Browsers that stored the rule refuse to open them and offer no way to continue.

Typical victims:

  • Mail and webmail: a hosting provider's webmail at mail.shop.com on plain HTTP or a certificate for the provider's own name. Mail delivery is unaffected, but browser access is not. While you are in the DNS zone, it is worth confirming your SPF, DKIM and DMARC records too.
  • Internal tools: an intranet, a router, NAS or printer given a friendly name inside the company domain.
  • Staging and preview hosts: self-signed or expired certificates are routine there, and with HSTS a certificate error can no longer be clicked past.
  • Third-party services on custom domains: status pages, help desks and email tracking links that do not offer HTTPS on your name.

Spot it: export the DNS zone and test every name with the SSL checker. Do this before adding the directive, not after.

Fix: move the service to HTTPS, move it off the domain, or leave includeSubDomains out until you can. Removing the directive does not free browsers that already stored it; they keep the rule until it expires or until they see a new header from the same host.

6. Preloading before every subdomain is ready

Preloading takes includeSubDomains and builds it into the browser, for every user, including people who have never visited. hstspreload.org asks for all subdomains to work over HTTPS, internal ones included, and warns that removal may take 6 to 12 weeks to reach most Chrome users and longer for other browsers. Its own guidance to tool makers is to never enable preload by default.

Fix: treat preload as the last step, months after a full year of includeSubDomains in production without incidents. If you are not certain you will keep every future subdomain on HTTPS, do not preload.

7. A wildcard certificate gap

A wildcard certificate for *.shop.com covers one level only. It does not cover the apex shop.com (which needs its own entry on the certificate) or deeper names such as api.eu.shop.com. Without HSTS, a visitor to an uncovered name sees a warning and can proceed. With includeSubDomains, the same mismatch is a hard stop.

Spot it: the SSL checker lists the names on the certificate. Compare them with every DNS name in the zone; our guide to checking an SSL certificate and fixing errors explains how to read a name mismatch.

Fix: add the apex and any deeper names to the certificate, or issue separate certificates for them.

8. The CDN and the origin disagree

With a CDN in front, two places can set HSTS: the edge and your server. Problems come from both directions:

  • Two different headers. The origin sends a year, the CDN adds six months. The standard tells browsers to process only the first Strict-Transport-Security header in a response, so which value wins depends on the order, which nobody chose.
  • Hostnames that bypass the CDN. Cloudflare applies its HSTS setting per hostname and only to proxied records. A record set to DNS only, often the apex or an API host, gets whatever the origin sends, which may be nothing.
  • Turning the CDN off. Cloudflare's documentation warns that if you remove HTTPS before disabling HSTS or waiting out the max-age, the site becomes inaccessible for that period. Pausing Cloudflare or moving nameservers away counts.

Fix: pick one place to set the header, remove it from the other, and test each hostname through the edge with the HTTP header checker.

Server configuration, tested

Each snippet below was tested in a local container on 28 October 2026 with a self-signed certificate, checking a page and a 404 response. They show includeSubDomains; leave it out until mistake 5 is ruled out.

Apache

Enable mod_headers (a2enmod headers on Debian and Ubuntu), then add the header inside every :443 virtual host, including the one that only redirects the apex:

Apache
<VirtualHost *:443>
    ServerName shop.com
    ServerAlias www.shop.com
    # SSLEngine, certificate lines and the rest of the site as before
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
</VirtualHost>

always matters: without it, Apache's Header set applies only to successful responses, so redirects and error pages go out without it. Tested on Apache 2.4.69, where both the page and the 404 carried the header.

Nginx

Use always, and repeat the header in every location block that has an add_header of its own:

Nginx
server {
    listen 443 ssl;
    server_name shop.com www.shop.com;
    # ssl_certificate lines as before

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

    location /assets/ {
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
        add_header Cache-Control "public, max-age=604800";
    }
}

On nginx 1.27.5, this version returned the header on the page, the stylesheet and the 404. Larger sites usually put the line in a small file and include it in each block, so it cannot be forgotten in the next one.

Caddy

Caddy obtains certificates and redirects HTTP to HTTPS automatically, but it does not add HSTS on its own; our test with no header directive returned none. Add it to the site block:

Text
shop.com, www.shop.com {
	header Strict-Transport-Security "max-age=31536000; includeSubDomains"
	# reverse_proxy, file_server and the rest as before
}

Tested on Caddy 2.11.7. Listing the apex in the same block also covers mistake 3.

Cloudflare

From Cloudflare's HSTS documentation: in the dashboard, go to SSL/TLS, then Edge Certificates, find HTTP Strict Transport Security (HSTS) and select Enable HSTS. Read and confirm the warning, then set:

  • Max Age Header: from 1 to 12 months, or 0 to disable.
  • Apply HSTS policy to subdomains: this is includeSubDomains.
  • Preload: adds the preload directive. You still have to submit the domain yourself.
  • No-Sniff Header: unrelated to HSTS; it adds X-Content-Type-Options: nosniff.

The setting applies only to HTTPS requests on proxied hostnames. If your origin also sends HSTS, remove it there (mistake 8).

How to roll out safely

Stepped chart of max-age rising from 300 seconds to one year in five stages
The 5 minute, 1 week and 1 month stages follow hstspreload.org. The 1 day step is optional, and each stage is waited out in full before the next.

hstspreload.org recommends ramping max-age up in stages, waiting the full length of each stage and watching for broken pages and changes in traffic before moving on. A plan in that spirit:

  1. List every hostname. Export the DNS zone. Test each name for a valid certificate.
  2. Start at max-age=300 on every HTTPS response of the hosts you are sure about, without includeSubDomains. Test with the checks in how to test HSTS headers.
  3. Move to 86400 (one day) after a quiet stage, then 604800 (one week), then 2592000 (one month), waiting out each in full.
  4. Add includeSubDomains at a short max-age once every subdomain passes, and ramp again.
  5. Settle on 31536000 (one year).
  6. Consider preload only after months at a year with no incidents, and only for a domain you will keep on HTTPS indefinitely.

At any stage, sending max-age=0 tells returning browsers to drop the rule. That escape hatch is why the short early stages are worth the patience: a mistake at five minutes costs five minutes.

The takeaway

Most HSTS problems are not exotic. The header is on the wrong port, the wrong host, the wrong blocks, or covers subdomains nobody checked. Test every hostname and several response types, keep one source of truth for the header, raise max-age in steps, and leave preload for last.

HSTS is one item in our security headers checklist, and the security headers checker shows the rest in one run. If you would rather we measure and fix it at your server or CDN, that is part of our website fixes work.

Tools mentioned in this post