Back to cheatsheets
Web Security
HSTS Configuration
Configure HTTP Strict Transport Security with preload list submission guidance.
What you'll learn
- HSTS header values
- Nginx HTTP-to-HTTPS redirect
How to use these snippets
- Click the Copy button next to any snippet to copy it to your clipboard.
- Paste the code into your project, IDE, or terminal.
- Replace placeholder values (like
example.comoryour-secret) with your actual data. - Review the code comments for important security notes and caveats.
- Try the interactive related tool to see the concept in action.
Code Snippets
Copy-paste code snippets
2 ready-to-use snippets for hsts configuration. Click copy and paste into your project.
HSTS header values
// Minimum recommended
Strict-Transport-Security: max-age=31536000
// Full recommended (2 years + subdomains + preload)
Strict-Transport-Security: max-age=63072000;
includeSubDomains; preload
// Preload submission requirements:
// 1. Serve HTTPS on all subdomains
// 2. max-age >= 31536000 (1 year)
// 3. includeSubDomains present
// 4. Redirect HTTP to HTTPS on same host
// 5. Submit at hstspreload.org
Nginx HTTP-to-HTTPS redirect
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name example.com www.example.com;
add_header Strict-Transport-Security
"max-age=63072000; includeSubDomains; preload" always;
}
Tool
Related ShieldX tool
Try this concept hands-on with the interactive tool.
100% Free · No signup · No cost
Generate something unguessable right now
148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.
Part of the Toolly ecosystem · secure.toolly.site