proxy_cache only if custom header is set by upstream
Valentin V. Bartenev
ne at vbart.ru
Tue May 15 15:58:18 UTC 2012
On Tuesday 15 May 2012 19:42:12 ThomasLohner wrote:
> Hi,
>
> 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?
>
The rewrite module works before the request is passed to upstream, so upstream
variables is empty on rewrite stage.
You can use the map directive which is evaluated at the time of use.
wbr, Valentin V. Bartenev
More information about the nginx
mailing list