Originally published on Sitecheckly.
The HSTS header tells browsers to use HTTPS for a domain after receiving the header over HTTPS. In the Sitecheckly survey, 40% of analyzed sites were missing it. Set Strict-Transport-Security on HTTPS responses, start with a short max-age, and add includeSubDomains or preload only after checking their risks. RFC 6797 defines HSTS.
The October 2026 Sitecheckly survey covered the Tranco top 10,000, using Tranco list 7462X. The ranking covers 2026-10-02 to 2026-10-31. Home pages were fetched on 2026-11-01, and 4,934 of 10,000 domains could be analyzed. The rest were mostly CDN, DNS and API hosts, sites that ask crawlers to stay away in robots.txt, or sites that blocked automated requests. See the methodology for how Sitecheckly runs its checks.
What does the HSTS header do?
HTTP Strict Transport Security, or HSTS, lets a host tell browsers to use HTTPS for future requests. While the policy is active, the browser upgrades HTTP requests before sending them. It also prevents users from clicking through certificate errors for that host.
A previously received policy cannot protect a browser's first visit. If that first request uses HTTP, the browser has not yet learned the site's policy. Browser preload lists can address that gap. These behaviors are explained in MDN's Strict-Transport-Security reference.
Start with this HTTPS response header:
Strict-Transport-Security: max-age=300
The directives control how long the policy lasts and how broadly it applies:
| Directive | Meaning | Safe rollout approach |
|---|---|---|
max-age=300 |
Store the policy for 300 seconds. Receiving the header again refreshes its expiration. | Use a short policy while testing, then increase it. |
includeSubDomains |
Apply the policy to subdomains as well as the host sending it. | Add it only after checking every affected subdomain. |
preload |
Signal willingness to be included in browser preload lists. It does not submit the domain by itself. | Treat it as a separate deployment decision. |
Browsers ignore HSTS received over plain HTTP. HTTPS must already work; HSTS does not install a certificate or repair an invalid one. See MDN's directive and processing guidance.
Preloading requires more than adding a directive. Review HTTPS readiness across subdomains, meet the submission requirements, and submit the domain separately. Removal from browser preload lists can take time. Check the current requirements at hstspreload.org before committing.
How do you add HSTS in Nginx?
Add this directive inside your existing HTTPS server block:
add_header Strict-Transport-Security "max-age=300" always;
The always parameter makes Nginx add the header regardless of the response status. Without it, add_header applies only to the status codes listed in the module documentation.
Check nested location blocks too. Under the default inheritance behavior, a block with its own add_header directives does not inherit the parent block's headers. A header configured at the server level may therefore be absent from a particular route. See the Nginx headers module documentation.
After editing:
- Test the Nginx configuration with your deployment's configuration-test command.
- Reload Nginx only after the test passes.
- Check a normal page, a redirect, and an error response at the public HTTPS URL.
Keep HTTP-to-HTTPS redirects in place. Browsers without a stored policy still need a way to reach HTTPS and receive HSTS. The distinction between insecure requests and learned HSTS policies is defined in RFC 6797.
How do you add HSTS in Apache?
With mod_headers enabled, add this directive inside the existing HTTPS virtual host:
Header always set Strict-Transport-Security "max-age=300"
Apache's always condition allows the header to be applied beyond successful responses, including error responses. Apache also maintains separate internal response-header tables, so headers set by an application or another module can require special care. See the Apache mod_headers documentation.
Test the Apache configuration, then reload the service using your deployment's normal process.
Inspect the final public response afterward. If both Apache and an upstream application set HSTS, check for duplicate headers. Prefer one configuration owner rather than maintaining competing policies in several places.
How do you enable HSTS in Cloudflare?
Use Cloudflare's dedicated HSTS setting:
- Select the domain in the Cloudflare dashboard.
- Open SSL/TLS, then Edge Certificates.
- Find HTTP Strict Transport Security (HSTS) and enable it.
- Read the warning and choose a short maximum age for the initial rollout.
- Leave includeSubDomains and preload off until you have checked their impact.
Confirm that HTTPS works before enabling the policy. Follow Cloudflare's HSTS setup and requirements for the available controls and rollback warnings.
After saving, inspect the public HTTPS response rather than only the origin response. Avoid managing conflicting HSTS values at Cloudflare and your origin. Choose which layer owns the policy and verify what visitors actually receive.
How do you add HSTS in Next.js?
For a project using CommonJS in next.config.js, add this header configuration. If the file already contains settings, merge the headers() function into the existing exported object.
module.exports = {
async headers() {
return [
{
source: '/:path*',
headers: [
{
key: 'Strict-Transport-Security',
value: 'max-age=300',
},
],
},
];
},
};
The headers() configuration sets response headers for matching paths. The /:path* pattern matches paths throughout the application. See the Next.js headers configuration reference.
Deploy the change and check the public HTTPS response. Do not stop at checking a local development server.
If your hosting platform or reverse proxy already manages HSTS, choose one layer to own it. Keep this application-level configuration only if it is the intended source of the public policy.
How do you add HSTS in Express?
Register middleware before the routes that should receive the header. Add this after creating your Express app:
app.use((req, res, next) => {
res.set('Strict-Transport-Security', 'max-age=300');
next();
});
The res.set() method sets the response header, and next() passes control to the following middleware or route. The header-setting method is defined in the Express response implementation.
Serve the application over HTTPS or terminate HTTPS at a trusted proxy. This middleware sets a header; it is not a TLS configuration.
Verify the public HTTPS response after deployment. If the proxy also sets HSTS, remove the duplicate configuration or make the proxy the sole policy owner.
How do you check HSTS and decide whether to preload?
Check the public HTTPS URL with Sitecheckly's free security headers checker. For a broader passive check, run the separate security audit. It is free, requires no sign-up, and audits the entered page, not the whole site.
You can also inspect the response from a terminal:
curl -I https://example.com/
Look for the deployed policy:
Strict-Transport-Security: max-age=300
Check redirect responses and their destinations separately. Test representative subdomains too, especially before broadening the policy.
Increase max-age after the trial
A short max-age is a rollout step, not necessarily the intended permanent setting. In the survey, 11% of analyzed sites were flagged for a short HSTS max-age.
Once HTTPS and header delivery are working as intended, increase the policy duration deliberately. Do not copy a long-lived policy into production before checking certificate renewal, redirects, and the subdomains you plan to cover.
Treat includeSubDomains and preload as separate decisions
Before adding includeSubDomains, inventory affected subdomains, including services operated by third parties. Confirm that each can remain available over HTTPS.
Before adding preload, review the current preload submission and removal guidance. Adding the directive alone does not enroll the domain, and removing the header is not an immediate way out of a browser preload list.
What to do next
- Pick one layer to manage HSTS.
- Deploy a short policy and inspect the public HTTPS response.
- Test before increasing its duration or scope.
- Review the security headers list and recommended values to check the other headers your page needs.
Frequently asked questions
Can I disable an HSTS policy?
Send Strict-Transport-Security: max-age=0 over HTTPS to tell browsers that receive it to remove the stored policy. Preloaded entries require a separate removal process. See MDN and hstspreload.org.
Does HSTS install an SSL certificate?
No. HSTS is a browser policy, not a certificate. HTTPS must already work for the host; see RFC 6797.
Do browsers accept HSTS over HTTP?
No. Browsers ignore an HSTS header received over insecure HTTP; the policy must be sent over HTTPS. See MDN.
Want to see how your own site does? Run a free audit at sitecheckly.com.
Figures in this article come from Sitecheckly's own audit data; see the methodology.
Top comments (0)