So I came up with a work around, this is specific as I had to bypass a cookie being set with every request.
I used a varible $miss_it this ensured that i would or would not be passing to the backend that would ignore the set-cookie header when a cookie existed or did not exist. I have the cookie only being set by a specific location which does not have the proxy_cache for that specific reason. I ended up doing it this way as I could not set the proxy_ignore_headers as a varible (which makes sense).
set $do_not_cache 0;
set $cache_key $scheme://$host$uri$is_args$args;
set $miss_it 1;
if ($http_cookie ~* "sdata" ) {
set $do_not_cache 1;
set $cache_key $scheme://$host$uri$is_args$args$cookie_sdata;
set $miss_it virtual.apache;
}
location ~* ^/blog {
include /etc/nginx/proxy.conf;
include /etc/nginx/gzip.conf;
include /etc/nginx/conf/cache-nocookie.conf;
if ($miss_it = 1 ) {
proxy_pass http://$miss_it;
error_page 502 = /apachecachecookie$uri;
break;
}
proxy_pass http://virtual.apache;
break;
}
location ^~ /apachecachecookie {
internal;
include /etc/nginx/proxy.conf;
include /etc/nginx/gzip.conf;
include /etc/nginx/conf/cache-nocookie.conf;
proxy_pass http://virtual.apache;
proxy_hide_header Set-Cookie;
proxy_ignore_headers X-Accel-Expires Cache-Control Expires Set-Cookie;
break;
}
cache-nocookie.conf:
if ($do_not_cache = 0){
set $cache_proxy_bypass 0;
set $cache_proxy_no_cache 0;
set $cache_cache_friendly_head hit;
}
if ($do_not_cache = 1){
set $cache_proxy_bypass 1;
set $cache_proxy_no_cache 1;
set $cache_cache_friendly_head miss;
}
if ($cache_cache_apache = miss) {
set $cache_cache_friendly_head miss;
}
proxy_ignore_headers X-Accel-Expires Cache-Control Expires;
proxy_cache_bypass $cache_proxy_bypass; #if 1 then bypass cache for response
proxy_no_cache $cache_proxy_no_cache; # if 1 then don't cache response
proxy_cache large;
add_header x-cachencache $cache_cache_friendly_head;
add_header x-cachecachekey $cachekey; # for debug see what cache key is
proxy_cache_key $cachekey;
add_header x-cacheproxy proxyname;
proxy_cache_valid 200 301 302 404 10m;