← All articlesHeaders
How to Set Up HSTS on Your Website (Nginx, Apache, Cloudflare)
By Marcus, Founder · 5 min read · 6/11/2026
HSTS (HTTP Strict Transport Security) is a header that tells browsers to only ever connect to your site over HTTPS. Once a browser sees it, it refuses plain HTTP for your domain for the duration of max-age — closing the window for downgrade and cookie-hijacking attacks.
The header
Strict-Transport-Security: max-age=31536000; includeSubDomains; preloadmax-age=31536000— one year, in seconds.includeSubDomains— apply to every subdomain.preload— opt into the browser preload list (only add when you are ready).
Nginx
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;Apache
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"Cloudflare
SSL/TLS → Edge Certificates → enable HSTS and set max-age to 12 months.
Preloading
Once HSTS is live and stable, submit your domain at hstspreload.org. Warning: removal is slow, so confirm every subdomain serves HTTPS first.
FAQ
What max-age should I use for HSTS?
+Is it safe to enable HSTS preload?
+Scan your own domain free
See which of these issues affect your site — with exact fixes.
Scan Your Domain — Free