HSTS header generator
Build a Strict-Transport-Security header for nginx, Apache or Caddy. Choose max-age, includeSubDomains and preload, and check the hstspreload.org rules.
How long a browser remembers to use HTTPS only. Start short, check that nothing breaks, then raise it.
With includeSubDomains, every subdomain must serve HTTPS with a valid certificate, including internal ones that share the domain. A subdomain that only speaks HTTP stops working in browsers that have seen this header.
Header
Strict-Transport-Security: max-age=31536000; includeSubDomains
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains"
}Send the header on HTTPS responses. Browsers ignore it over plain HTTP, so also redirect HTTP to HTTPS.
Preload list requirements
- Metmax-age is at least 31536000 seconds (one year)
- MetincludeSubDomains is present
- Not metpreload is present
This header would not be accepted by hstspreload.org. The site must also have a valid certificate, redirect HTTP to HTTPS on the same host, and serve every subdomain over HTTPS, and the header must be sent by the base domain.
Everything you type here stays in your browser. Nothing is sent to HardenKit or to anyone else.
How to use the HSTS header generator
- Choose a max-age. Use a short one for the first test, and a year or more for production.
- Switch on includeSubDomains once every subdomain serves HTTPS.
- Add preload only if you intend to submit the domain to hstspreload.org.
- Copy the line for your server and check the preload requirements below it.
About this tool
HTTP Strict Transport Security (HSTS) tells a browser to use HTTPS for a site for a set time, and to refuse to continue when the certificate is not valid. Without it, a visitor who types the bare domain makes a first request over plain HTTP, and someone on the same network can intercept that request and keep the visitor off HTTPS.
The header has three parts. max-age is how long the browser remembers the rule, in seconds. includeSubDomains extends it to every subdomain. preload states that you want the domain added to the list built into browsers, which protects even the very first visit. The preload list at hstspreload.org accepts a domain only with a max-age of at least one year, includeSubDomains and preload.
The mistake to avoid is going straight to the strongest setting. includeSubDomains breaks any subdomain that still serves plain HTTP, and preloading takes months to undo because the list ships inside browser releases. Start with a short max-age, confirm every subdomain works over HTTPS, raise it to a year, and add preload last.
Sources
Questions
One year (31536000 seconds) is the usual production value and the minimum for preloading; two years is the value hstspreload.org shows in its example header. While testing, use a few minutes, then a week, then a month, so a mistake wears off quickly.
A valid certificate, a redirect from HTTP to HTTPS on the same host, HTTPS on all subdomains, and an HSTS header on the base domain with max-age of at least 31536000, includeSubDomains and preload. The domain is then submitted at hstspreload.org.
You can ask for removal, but it reaches users only as they update their browsers, which takes months. Until then every subdomain must keep working over HTTPS. Treat preloading as permanent.
No. Browsers ignore the header on a plain HTTP response, because an attacker on the network could have added or removed it. Send it on HTTPS responses and redirect HTTP to HTTPS.