session es | en ·
16k.es

notes from the command line

~ / notes / Adding proper security headers to NGINX

Adding proper security headers to NGINX

· 1 min read · #security #web

Add the right security headers to nginx because we all like to get an “A” in securityheaders.com

security headers

After auditing quite a few sites, I tested my own site for security headers. And guess what happened?

security report “D”

Wow, this had to be fixed :D

I just added:

# Set security headers
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Content-Security-Policy "default-src 'self'";
add_header Referrer-Policy "no-referrer";

# Set HSTS to 365 days
add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload' always;

security report “A”

I will add the new Permissions-Policy later, once I read about -and hopefully understand- it.

© 2026 lmrioja · mastodon · built with Hugo, served static