proxy_cache only if custom header is set by upstream

ThomasLohner nginx-forum at
Tue May 15 15:42:12 UTC 2012


i know how to *prevent* caching if custom headers are set by upstream
with proxy_cache_bypass and proxy_no_cache.

This time i'd like to do the opposite, i want the response to be cached
*only* if a custom header is present.

I tried something like:

set $nocache 1;

proxy_no_cache $nocache;


if ($upstream_http_myheader = 1) {

  set $nocache 0;


But this doesn't work. Any ideas or am i missing something?


Thomas Lohner

Posted at Nginx Forum:,226461,226461#msg-226461

More information about the nginx mailing list