Welcome! Log In Create A New Profile

Advanced

add_header is not working in certain locations

August 13, 2014 02:28AM
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

#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;
}

Example 2:
Request is the same and this chain of locations is recommended by drupal community.
location / {
#Does not work
if ($arg_region) { add_header Set-Cookie "__geoip_country__=$arg_region;Path=/"; }
try_files $uri @rewrite;
}

location @rewrite {
rewrite ^ /index.php;
}


location ~ \.php$ {
#This works
if ($arg_region) { add_header Set-Cookie "__geoip_country__=$arg_region;Path=/"; }
...
fastcgi_intercept_errors on;
fastcgi_pass fpm-backend;
}
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: 281
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