Welcome! Log In Create A New Profile

Advanced

Re: add_header not allowed in server if blocks?

Maxim Dounin
June 14, 2010 09:44PM
Hello!

On Mon, Jun 14, 2010 at 07:04:21PM -0400, steveh wrote:

> I'm trying to add support for google chrome frame to our nginx
> config the simple way would be to include a fragment in each
> server block which looks something like:
>
> if ( $http_user_agent ~ chromeframe ) {
> add_header X-UA-Compatible "chrome=1";
> }

Just adding X-UA-Compatible unconditionally should be sufficient,
but if you really want to return it to chrome frame only, try
something like this:

set $tt "";

if ($http_user_agent ~ chromeframe) {
set $tt "chrome=1";
}

add_header X-UA-Compatible $tt;

Note well: add_header used in location would reset inherited
add_header directives (usual array inheritance rules apply), so
you have to repeat add_header in such locations (if any).

> The problem is for some reason add_header isn't allowed in
> server-if blocks on location-if blocks. I can't see or think of
> a reason why this shouldn't be allowed?

Actually, the real question is "why it's allowed in 'if in
location' blocks". The answer seems to be "uh, it was a mistake".
See here for details:

http://wiki.nginx.org/IfIsEvil

> So I tried adding it and it seems to work without a problem. The
> following patch, made against 0.8.40, adds server if block
> support for both expires and add_header.

You didn't tested it well enough. It does nothing but removes
config parsing error.

Maxim Dounin

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

add_header not allowed in server if blocks?

steveh June 14, 2010 07:04PM

Re: add_header not allowed in server if blocks?

steveh June 14, 2010 08:29PM

Re: add_header not allowed in server if blocks?

Maxim Dounin June 14, 2010 09:44PM

Re: add_header not allowed in server if blocks?

steveh June 14, 2010 09:58PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 211
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready