An SSL certificate encrypts the connection, but it does not tell the browser how strictly to protect your visitors. HTTP security headers do. A few lines in your server configuration can stop downgrade attacks, clickjacking, MIME sniffing and many script injection attacks. This guide explains the headers worth adding, safe starting values and how to roll them out on Nginx, Apache or Cloudflare without breaking your site.
The headers that matter
| Header | Protects against | Safe starting value |
|---|---|---|
| Strict-Transport-Security (HSTS) | Downgrade to HTTP, cookie theft on insecure networks | max-age=31536000; includeSubDomains |
| Content-Security-Policy (CSP) | Injected scripts (XSS), unwanted third-party code | Start in report-only mode (see below) |
| X-Content-Type-Options | Browsers guessing file types and running uploads as scripts | nosniff |
| X-Frame-Options / CSP frame-ancestors | Clickjacking (your site loaded inside a hidden frame) | SAMEORIGIN or frame-ancestors 'self' |
| Referrer-Policy | Leaking full URLs with private data to other sites | strict-origin-when-cross-origin |
| Permissions-Policy | Unneeded access to camera, microphone, location | camera=(), microphone=(), geolocation=() |
The old X-XSS-Protection header is deprecated in modern browsers; rely on CSP instead.
HSTS: do it in steps
HSTS tells browsers to use HTTPS only for your domain for the time set in max-age. It is powerful and hard to undo, because browsers remember it.
- Make sure every page and subdomain works on HTTPS with a valid certificate. See free SSL with Certbot and fixing mixed content.
- Start with a short value, such as
max-age=300, and check nothing breaks. - Increase to
max-age=31536000(one year). AddincludeSubDomainsonly when every subdomain, including mail and old tools, supports HTTPS. - Consider the browser preload list (
preload) only after this has run safely for a while; removal from the list takes a long time.
Content-Security-Policy without breaking the site
CSP lists the sources allowed to load scripts, styles, images, fonts and frames. A strict policy blocks injected code, but a wrong policy can break analytics, chat, payment widgets or your page builder. Roll it out like this:
- Begin with
Content-Security-Policy-Report-Only, which reports violations without blocking. - Start with a base policy, for example:
default-src 'self'; img-src 'self' data: https:; script-src 'self' https://www.googletagmanager.com; style-src 'self' 'unsafe-inline'; frame-ancestors 'self'; object-src 'none'; base-uri 'self' - Open the browser console on key pages (home, product, checkout, contact) and add the domains you really need.
- When the console is clean for a while, switch to the enforcing
Content-Security-Policyheader.
Even a partial policy helps: frame-ancestors, object-src 'none' and base-uri 'self' are low-risk wins.
How to add headers
Nginx
Inside the server block for HTTPS:
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;add_header X-Content-Type-Options "nosniff" always;add_header X-Frame-Options "SAMEORIGIN" always;add_header Referrer-Policy "strict-origin-when-cross-origin" always;add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
Note: in Nginx, an add_header inside a location block replaces the ones from the server block. Test with nginx -t, then reload.
Apache / .htaccess
Header always set X-Content-Type-Options "nosniff"Header always set Referrer-Policy "strict-origin-when-cross-origin"
This needs the mod_headers module, which is enabled on most cPanel and LiteSpeed hosts.
Cloudflare
If your site is behind Cloudflare, you can enable HSTS in the SSL/TLS settings and add other headers with response header transform rules. See setting up Cloudflare with your hosting.
Check your headers
- Run
curl -I https://yourdomain.comand read the response headers. - In browser DevTools, open the Network tab, click the main document and look at Response Headers.
- Re-check after plugin updates, CDN changes or moving servers, because headers can be lost.
Headers are one layer
Security headers reduce browser-side attacks; they do not replace updates, strong passwords, a firewall and backups. On a VPS, start with SSH keys, UFW and Fail2ban. Every IM HOST plan includes free SSL, and you can upgrade to OV, EV or wildcard certificates when your business needs them. Need help adding headers safely? Contact our support team.



