How to add security headers to your website
Updated 11/29/2026
Security headers are instructions the server sends to the browser to block common attacks. They are added in a few lines.
Nginx
In the server block, add:
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
nginx -t && systemctl reload nginx
What these headers do
- X-Frame-Options: prevents the site from loading in an iframe (anti-clickjacking protection).
- X-Content-Type-Options: stops the browser from guessing file types.
- Referrer-Policy: controls what referrer information is sent to other sites.
- Strict-Transport-Security: forces HTTPS for future visits.
Content Security Policy
For advanced protection against injected scripts, add a CSP header, but test it carefully so you do not block legitimate resources:
add_header Content-Security-Policy "default-src 'self'" always;
Check the result with free online header-analysis tools. See also how to add HTTPS.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
Single sign-on for your applications with authentik
One account for all your team's apps: first sign-in, users, an OpenID Connect application and two-factor authentication.
Updated 11/29/2026SecurityPasswordless sign-in with Pocket ID
Passkeys for your applications over OpenID Connect: first sign-in, colleagues and connecting an application.
Updated 11/29/2026SecurityHow to protect your server from brute-force attacks with fail2ban
fail2ban automatically bans IPs that repeatedly try wrong passwords. Here is how to install and configure it.
Updated 11/29/2026