Skip to content

HTTP security headers

Security headers are instructions your server sends the browser with every page to protect it: always use HTTPS (HSTS), limit where scripts load from (Content-Security-Policy), prevent it from being framed (X-Frame-Options) and stop file-type guessing (X-Content-Type-Options).

Published · ganyant

Which ones matter most?

Strict-Transport-Security (HSTS): forces HTTPS every time. Content-Security-Policy: stops XSS by limiting which scripts can run. X-Frame-Options or frame-ancestors: stops another site from showing yours in an iframe to trick clicks. X-Content-Type-Options: nosniff. Referrer-Policy: controls which address is shared when leaving your site.

How do I add them in nginx?

Inside the server block: 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; and add_header Referrer-Policy "strict-origin-when-cross-origin" always;. Then run nginx -t and reload.

And in Apache?

With the headers module on: Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains", Header always set X-Content-Type-Options "nosniff", Header always set X-Frame-Options "SAMEORIGIN" and Header always set Referrer-Policy "strict-origin-when-cross-origin".

Why is CSP the hardest?

Because it has to list everything your site loads (scripts, styles, fonts, analytics). Start with Content-Security-Policy-Report-Only to see what would break without blocking anything, and avoid unsafe-inline and the * wildcard, which make it almost useless.

How does ganyant do it?

ganyant’s security audit checks these headers on every site you monitor, along with cookies, the redirect to HTTPS and mixed content. Each finding comes with how to fix it for nginx, Apache, Cloudflare and others, and the grade climbs from F to A+ as you fix them.

Put it into practice, free

ganyant monitors your sites from 4 continents, audits their security every day and publishes your status page. Free plan.