Adding headers to all error pages

Nick Rickard nick at nickrickard.co.uk
Tue Nov 17 13:59:25 UTC 2026


> 
> we're largely relying on the internal error pages in nginx, with a few 
> exceptions where we serve static HTML files. Lately it has been required 
> of us to include the response header
>      X-Content-Type-Options: nosniff
> in every response - including all possible error pages.
> The ease may depend on your version of nginx.

server {
    ...
    add_header X-Content-Type-Options "nosniff" always;
    ...
}

Should add the header to all responses including 403, 404, etc.

If you're on nginx 1.30 or later then add_header_inherit in the location 
blocks should inherit this setting and still allow extra child rules. 
(I'm not on 1.30 so not tested.) If you're earlier than 1.30 then 
add_header directives in child locations will interfere with this so 
perhaps less straightforward.


More information about the nginx mailing list