Add the Strict-Transport-Security (HSTS) header on nginx
Why it matters
Without HSTS, a browser that is sent to the http:// address first can be intercepted before it reaches the secure site. The header tells browsers to use HTTPS only, for as long as you specify.
Staged change. Do this in stages and check each one before the next, so a mistake does not break your site or your mail.
The fix
- Put the directive in the server block that listens on 443. The always parameter makes nginx send it on error responses too.
- add_header directives are inherited from the enclosing level only when the current level has none. If a location block defines its own add_header, repeat this line there.
- Test with nginx -t, reload, and check with curl -sI.
- Raise max-age in the stages from the generic steps (86400, then 2592000, then 31536000), reloading each time.
/ etc/ nginx/ conf.d/ site.conf
add_header Strict-Transport-Security "max-age=300" always; Related
- Reported by the HSTS check
- Fix the malformed Strict-Transport-Security header
- Re-enable HSTS (max-age is zero)
- Raise the HSTS max-age
- Decide whether to add includeSubDomains
- Meet the HSTS preload requirements or remove preload
- Consider submitting the domain to the HSTS preload list
- Send HSTS on the redirect visitors meet first
Scan your domain to see whether this applies to you.