Welcome! Log In Create A New Profile

Advanced

Re: add_header is not working in certain locations

Francis Daly
August 13, 2014 07:34PM
On Wed, Aug 13, 2014 at 02:28:27AM -0400, bodomic wrote:

Hi there,

> Hi all, I've got strange behavior that I don't understand in two different
> configs. I'll post examples below, in both of them I use add_header two
> times and one of them is not working while second does.
>
> Example 1:
> Request is: http://hostname/?region=XX

In this case, for location matching the request is "/", so the best-match
location for that will be used.

> #This location adds header, so it's frankly the only reason I use it in my
> config. If I set location to "~ .*", I'll get header set also.
> location = / {
> if ($arg_region) {
> add_header Set-Cookie "__geoip_country__=$arg_region;Path=/";
> }
> proxy_pass http://backend;
> }
> #If I remove the exact match above, I'll not get header set. Even if it's
> the only location in whole config and all site is working from there for
> sure.
> location / {
> if ($arg_region) { add_header Set-Cookie
> "__geoip_country__=$arg_region; path=/" ;}
> proxy_pass http://backend;
> }

It works for me.

In this case, I do get the Set-Cookie header when I have either one of
the two location{} blocks as the only location{} in the configuration. I
think you say that you do not get the Set-Cookie header in the second
case -- can you provide a complete, small, config that shows that?

> Example 2:
> Request is the same and this chain of locations is recommended by drupal
> community.

For these ones, I'm not sure how to set up a simple test.

Note, though, that you are using "if" inside "location". Generally, it is
not wise to do that unless you understand exactly what your configuration
actually means.

http://wiki.nginx.org/IfIsEvil for details.

Is there a link to this drupal recommendation? It isn't obvious to
me from the first few results for "nginx site:drupal.org" or "drupal
site:nginx.org"

> location / {
> #Does not work
> if ($arg_region) { add_header Set-Cookie
> "__geoip_country__=$arg_region;Path=/"; }
> try_files $uri @rewrite;
> }

That one seems to be "# try_files wont work due to if" on the IfIsEvil page.

Cheers,

f
--
Francis Daly francis@daoine.org

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

add_header is not working in certain locations

bodomic August 13, 2014 02:28AM

Re: add_header is not working in certain locations

Francis Daly August 13, 2014 07:34PM

Re: add_header is not working in certain locations

bodomic August 14, 2014 08:50AM

Re: add_header is not working in certain locations

itpp2012 August 14, 2014 09:24AM

Re: add_header is not working in certain locations

bodomic August 14, 2014 10:07AM

Re: add_header is not working in certain locations

bodomic August 14, 2014 10:16AM

Re: add_header is not working in certain locations

Francis Daly August 14, 2014 01:18PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 180
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