Skip to content

Did you know?

An add_header inside an Nginx location drops every header inherited from the server block, including HSTS.

Repeat security headers in each location with its own add_header, or use add_header_inherit merge on Nginx 1.29.3+.

  • Web servers
  • Applies to Nginx
  • Last checked

Explained

Nginx only inherits add_header directives from the enclosing level when the current level has none of its own. So this /static/ location sends its Cache-Control header, but no Strict-Transport-Security header:

server {
    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;

    location /static/ {
        add_header Cache-Control "public, max-age=86400";
    }
}

Repeat the security headers in that location (an include snippet keeps it tidy), or on Nginx 1.29.3 and newer, add add_header_inherit merge; to the location. Older versions, including the Ubuntu, Debian and RHEL packages, reject that directive.

Learn more

← All tech tips · Suggest a fix

Back to top