Force HTTPS connections and protect your visitors from downgrade attacks.
HSTS (HTTP Strict Transport Security) is a security mechanism that forces browsers to use exclusively HTTPS to communicate with your site. Once the HSTS header is received, the browser will refuse any HTTP connection for the specified duration, even if the user explicitly types http://.
HSTS protects against several types of attacks, including man-in-the-middle (MITM) attacks that attempt to downgrade the connection from HTTPS to HTTP. Without HSTS, an attacker on a public WiFi network could intercept the first HTTP request before the redirect to HTTPS.
This guide explains how to configure HSTS correctly, precautions to take, and how to submit your domain to the preload list for maximum protection.
HSTS provides several security benefits:
The HSTS header consists of several directives:
Follow these steps to enable HSTS progressively:
How to configure HSTS on common servers:
# Nginx
server {
listen 443 ssl http2;
# ... SSL configuration ...
# HSTS header (adjust max-age progressively)
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
}
# Apache (.htaccess or vhost)
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</IfModule>
# PHP (in your application)
header("Strict-Transport-Security: max-age=31536000; includeSubDomains; preload");
# Verify with curl
curl -I https://example.com | grep -i strict
The header should only be sent on HTTPS responses (not HTTP). Use "always" in Nginx to include it even on errors.
Avoid problems with these recommendations:
Visitors won't be able to access your site at all. The browser will refuse any non-HTTPS connection and the SSL error will prevent HTTPS access.
You can send max-age=0 to ask browsers to forget HSTS. But visitors who already received the old header will have to wait for it to expire.
A list of HSTS domains built into browsers. Your site will be HTTPS from the first visit, without waiting for the first header.
Submit a removal request at hstspreload.org. The process takes several months because browser updates are slow.
Yes, but each subdomain must have a valid certificate. A wildcard SSL is recommended in this case.
MoniTao checks SSL certificate validity. For HSTS, use securityheaders.com to analyze your security headers.
HSTS is an essential security layer for any HTTPS site. Configure it progressively and carefully to avoid blocking access to your site.
With HSTS and MoniTao SSL monitoring, your site is protected from downgrade attacks and you're alerted before any certificate expiration.
Start free, no credit card required.