'add_header' no longer allowed inside 'if', even though document says it is?

Daniël Mostertman daniel at mostertman.org
Wed Feb 18 17:02:24 UTC 2015


Hi again,

And ugh, yet again realising what I did wrong right after hitting "send":

Daniël Mostertman schreef op 18-2-2015 om 17:57:
> tl;dr: I want do have an add_header inside an if {}. nginx 1.7.10 
> won't let me.
Because I didn't put the if inside a location.

> According to both http://wiki.nginx.org/IfIsEvil and 
> http://nginx.org/en/docs/http/ngx_http_headers_module.html (see 
> Context of add_header), it should be allowed inside an if.
> But yet:
>
> root:~# nginx -t
> nginx: [emerg] "add_header" directive is not allowed here in 
> /etc/nginx/sites-enabled/webtv-test:37
> nginx: configuration file /etc/nginx/nginx.conf test failed
> root:~#
>
> What am I doing wrong, if anything? And if I can avoid using "if" like 
> that, I'd obviously prefer that.

Answering my own question: "add_header" can only be inside an "if" 
that's inside a "location".
I have no "location" for the root, so I figured it could be inside "server".

Daniël



More information about the nginx mailing list