add_header is not working in certain locations

bodomic nginx-forum at nginx.us
Wed Aug 13 06:28:27 UTC 2014


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

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,252523,252523#msg-252523



More information about the nginx mailing list