ipdetecto.com logo
ipdetecto.com
My IPSpeed
Knowledge Hub
HomeKnowledge HubNginx Security Headers Configuration
© 2026 ipdetecto.com
support@ipdetecto.comAboutContactPrivacyTermsllms.txt
Privacy & Security
5 MIN READ
Apr 19, 2026

Nginx Security Headers Configuration

HSTS, CSP, CORP/COOP, Referrer-Policy, Permissions-Policy—header placement and add_header inheritance pitfalls.

Security headers instruct browsers how to treat your content. nginx injects them with add_header, but headers can be dropped or duplicated across nested location blocks—often you centralize snippets and use always so error pages receive the same policy. Start Content-Security-Policy in report-only mode, tighten gradually, and pair Strict-Transport-Security only when HTTPS is stable everywhere.

HeaderRoleCaveat
Strict-Transport-SecurityForces HTTPS for a durationLong max-age is hard to unwind
Content-Security-PolicyRestricts scripts and loadsBreaks third-party embeds if too tight
Cross-Origin-Opener-PolicyIsolates browsing contextCan affect cross-window integrations

Related

nginx SSL, nginx configuration, server blocks, Apache SSL (compare)

Frequently Asked Questions

Q.Why use add_header with the always flag?

Without always, nginx may omit headers on error responses—policies should usually apply to 4xx and 5xx pages too.

Q.Why do headers disappear in nested locations?

Child locations replace parent header lists unless you re-include shared snippets—inheritance is not merged by default.

Q.How should I roll out Content-Security-Policy?

Begin with Content-Security-Policy-Report-Only, collect violations, then enforce once sources are accurate.

Q.What does HSTS preload imply?

Preload lists require HTTPS on apex and subdomains with a long max-age—mistakes can lock users out until fixed.

Q.What is Permissions-Policy used for?

It disables or scopes powerful browser features such as camera, microphone, and geolocation per origin.

Q.How does Referrer-Policy help privacy?

It limits how much URL data is sent to third parties on navigation and subresource requests.

Q.Should I rely on X-Frame-Options or CSP for clickjacking?

Prefer CSP frame-ancestors for modern browsers; X-Frame-Options is simpler but less expressive.

Q.What is cross-origin isolation?

COOP and CORP combine with Cross-Origin-Embedder-Policy to enable stronger process isolation for some advanced APIs.
TOPICS & TAGS
nginx security headersCSPHSTSadd_header