ShieldX Toolly
Open a tool Donate
Home Home
Blog Blog
FAQ FAQ
Open a tool Donate
Back to cheatsheets
Web Security

HSTS Configuration

Configure HTTP Strict Transport Security with preload list submission guidance.

2 snippets Beginner hsts-checker
HSTSpreloadmax-ageincludeSubDomains

What you'll learn

  • HSTS header values
  • Nginx HTTP-to-HTTPS redirect

How to use these snippets

  1. Click the Copy button next to any snippet to copy it to your clipboard.
  2. Paste the code into your project, IDE, or terminal.
  3. Replace placeholder values (like example.com or your-secret) with your actual data.
  4. Review the code comments for important security notes and caveats.
  5. 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

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.

Open the toolkit

Part of the Toolly ecosystem · secure.toolly.site