fastcgi_cache_bypass. Need some explain.

Maxim Dounin mdounin at mdounin.ru
Thu Sep 11 14:29:53 UTC 2014


Hello!

On Thu, Sep 11, 2014 at 12:01:00PM +0300, wishmaster wrote:

> Hi,
> 
> I am attempting to configure nginx to avoid caching some data.
> 
>         map $http_x_requested_with $no_cache {
>             default 0;
>             "XMLHttpRequest" 1;
>         }
> 
>         fastcgi_cache_bypass $no_cache;
>         fastcgi_no_cache $no_cache;
> 
> With above configuration exceptions works fine, but with below - not. Why?
> 
>         fastcgi_cache_bypass $http_x_requested_with;
>         fastcgi_no_cache $http_x_requested_with;
> 
> With above config all requests (not only with "X-Requested-With: XMLHttpRequest") is bypassed.

Most likely there is some subtle error in the configuration - 
e.g., missing ";" after fastcgi_cache_bypass.

The fastcgi_cache_bypass gets an arbitrary number of arbitrary 
parameters, and something like:

    fastcgi_cache_bypass $http_x_requested_with
    fastcgi_no_cache $http_x_requested_with;

is perfectly valid from syntax point of view, but really means 
fastcgi_cache_bypass with the "$http_x_requested_with", 
"fastcgi_no_cache" and "$http_x_requested_with" parameters.  And 
the "fastcgi_no_cache" parameter is always true, hence all 
requests bypass the cache.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list