add_header isn't taking effect

Francis Daly francis at
Sat Aug 18 23:46:27 UTC 2012

On Sat, Aug 18, 2012 at 04:31:54PM -0700, Michael Shadle wrote:

Hi there,

> It actually seems like if I add_header in one scope somewhere it will
> ignore in another.

Yes, that's the expected behaviour for nginx configuration directives.

A request is handled in exactly one location; the configuration in or
inherited into that location is what matters; inheritance or merging is
by replacement.

> For example I have one gratuitous add_header at the server {} level -
> with a different name.
> Then I add one on the location level.

In this location, only this one will apply. In another location, only
the server-level one will apply.

> Then I have one come from the upstream.

nginx doesn't care about headers being added; it cares about the
add_header directive. So this line should not influence the outcome.

> I could reproduce it reliably by adding an add_header somewhere and it
> would drop the other one out. I also have two environments with nearly
> exact configurations and one passes all 3 headers I want vs. 2 headers
> consistently. Very odd.

I suspect that if you compare the nearly exact configurations, you'll
spot an important difference.

If you want a specific extra add_header in a location, you must also
repeat the other add_header directives within that location.

Francis Daly        francis at

More information about the nginx mailing list