Our server sends 5 security headers on every HTML response. When we checked them for this guide on 7 October 2026, we found that one of our own cache rules switched all 5 off for the files it covers. The home page showed the headers, the configuration listed them, and a curl on a stylesheet returned none. A line in a config file proves nothing until you have requested the files that matter, so this guide spends as much time on testing as on the headers themselves.
The set we run, and what each line does
The set is 5 headers. None needs a library, and each is a single line of server configuration. The values below are the ones our server sends, as seen with curl on 7 October 2026.
| Header | What it tells the browser | Our value |
|---|---|---|
Strict-Transport-Security | Use HTTPS for this host, and its subdomains, for the stated time, even if a link says http | max-age=63072000; includeSubDomains |
X-Content-Type-Options | Trust the declared content type, do not guess another one by sniffing the file | nosniff |
Referrer-Policy | How much of your page address is sent to the next site when a visitor follows a link | strict-origin-when-cross-origin |
X-Frame-Options | Whether other sites may display your page inside a frame | SAMEORIGIN |
Permissions-Policy | Which browser features (camera, microphone, location) the page and its embeds may use | camera=(), microphone=(), geolocation=() |
The HSTS value is 2 years (63072000 seconds), which is where you end up, not where you start: a browser that has seen the header refuses plain HTTP for that whole time, so the HTTPS and HSTS guide walks through a gradual ramp from 5 minutes. includeSubDomains extends the rule to every subdomain, so add it only when all of them serve HTTPS. We do not send the preload directive. The preload list asks for a max-age of at least 31536000, includeSubDomains and preload, and getting a domain off the list again takes months.
X-Frame-Options is the older way to stop clickjacking. MDN describes the CSP directive frame-ancestors as its more flexible replacement, and we keep the older header until we ship a CSP. Referrer-Policy states a value that recent browsers already apply when no policy is set, so sending it makes the behavior explicit instead of assumed. Permissions-Policy switches off features we never use; if you embed a map that needs location, loosen that line.
Copy-paste configuration
In nginx, put the lines in the server block that serves your pages. The always parameter matters: without it nginx adds the header only for a short list of success and redirect status codes, and your 404 and 500 pages go out bare.
server {
# listen, server_name, ssl_certificate ...
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
}
Apache needs the mod_headers module (a2enmod headers on Debian and Ubuntu). Put the block in the virtual host, or in .htaccess if you have no access to the server configuration. Header always set is the equivalent of nginx’s always.
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
</IfModule>
Test the syntax before reloading: nginx -t && systemctl reload nginx for nginx, apachectl configtest && systemctl reload apache2 for Apache. If you have just switched HTTPS on, replace the HSTS value with max-age=300 for the first days.
Roll them out in this order
On a live site, add the headers in order of how little each can break, and look at the browser console after every step. This order is our recommendation. Start with X-Content-Type-Options: it can only break a file served with the wrong content type, such as a script delivered as text/plain, which the browser now refuses to run instead of guessing. Next comes Referrer-Policy. At this value other sites receive only your origin, not the full page address, when a visitor follows a link off your site, so an affiliate or analytics partner that reads the full referring path stops seeing it.
Then add X-Frame-Options. It breaks any legitimate embedding of your pages on other sites, so skip it if you offer embeds. Permissions-Policy follows: it breaks an embedded widget that needs a feature you switched off, which is easy to see and easy to undo. HSTS goes last because it is the only header whose mistakes last. Once a browser has cached includeSubDomains, a subdomain that cannot serve HTTPS becomes unreachable for that visitor until the max-age runs out, and no change on your server can reach into their browser to undo it.
The add_header trap we fell into
The nginx documentation says that add_header directives are inherited from the previous level only if the current level defines none. Our server block defined the 5 security headers. A location block further down, for the fingerprinted CSS and JavaScript folder, defined its own add_header Cache-Control "public, immutable". That single line made nginx forget all 5 headers for that folder. We confirmed it on a stylesheet on 7 October 2026: the home page and a made-up URL returning 404 each carried 5 of the 5 headers, the stylesheet carried 0. We repeated the 5 lines inside that location, and in the one that serves our share images, the same day.
The fix is to repeat the headers wherever a location adds its own. A snippet file keeps them in a single place:
# /etc/nginx/snippets/security-headers.conf holds the 5 add_header lines
server {
include snippets/security-headers.conf;
location /assets/ {
expires 1y;
add_header Cache-Control "public, immutable";
include snippets/security-headers.conf;
}
}
To catch the same mistake on your server, request 3 kinds of URL, not just the home page: a normal page, a URL that does not exist and a static file. Replace the domain and the file path with yours:
for path in / /does-not-exist /assets/site.css; do
echo "== $path"
curl -sI "https://example.com$path" | grep -iE '^(strict-transport|x-content-type|referrer-policy|x-frame|permissions-policy)'
done
Each URL should print 5 lines. The same loop works against an Apache server, because the test does not care which software answers.
Content-Security-Policy: what we have not shipped, and a safe way in
We do not send a Content-Security-Policy yet. MDN explains why it is worth the trouble: a CSP limits where scripts, styles, images and frames may load from, which blunts cross-site scripting, and frame-ancestors handles clickjacking. It also explains why it is easy to get wrong. MDN prefers nonces or hashes to allowlists of domains, advises avoiding unsafe-inline and unsafe-eval, and recommends introducing a policy gradually, starting in report-only mode.
Our reason for waiting is practical, and it is our judgment rather than a rule. This site shows no ads today. Once an ad tag and a consent platform are added, the page loads scripts and frames from third-party domains, and a policy written now would have to be rewritten. We would rather observe the real set of requests first. Because we run no ads yet, we cannot give you a tested AdSense policy, and we will not pretend to.
For a static content site, this is a reasonable first policy to send in report-only mode. It blocks nothing; it only logs what it would have blocked.
Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; object-src 'none'; base-uri 'self'
Send it with add_header ... always; in nginx or Header always set ... in Apache, exactly like the other 5. Then browse your own site with the browser’s developer console open: each violation is logged there with the directive and the blocked address. Many generators inline small styles or scripts, so expect early noise; each item is either moved into a file, hashed, or accepted. A static site cannot generate a fresh nonce per request without help from the server, so hashes are the usual answer for inline code that never changes. If you carry ads, run the report-only policy on a page with the ad code for a week of normal traffic before you enforce anything.
What headers do not do
These headers instruct browsers. They protect your visitors from clickjacking, content-type confusion and some leaks, and they do nothing to keep scanners away from your server. In the 14.8 days covered by our server log study, 3,304 requests (63.4 % of the total) were scanner probes for files such as .env and WordPress paths. None of the sensitive paths they asked for returned a 200, and no header made the difference: the site is static, with no WordPress and no PHP, so there was nothing to find.
You can check the set with our SEO checker. Its security headers category runs 5 checks: HSTS, nosniff, framing protection (X-Frame-Options or a CSP frame-ancestors), Referrer-Policy and a CSP. HSTS carries double the weight of the others, and the checker does not test Permissions-Policy.
Quick answers
Do security headers help with SEO or AdSense approval?
None of the Google documentation we rely on lists them as a ranking factor or an AdSense requirement. Treat them as protection for your visitors' browsers. A valid certificate and a redirect from HTTP to HTTPS are different: Google's AdSense help names both when it explains why a site may not be ready to show ads.
Can I drop X-Frame-Options once I send a CSP with frame-ancestors?
MDN describes frame-ancestors as the more flexible replacement. Keep both while the new policy runs in report-only mode, and remove X-Frame-Options only after the enforced policy is live and you have tested that your own pages still frame what they should.