Home > Software engineering >  two differents fastcgi_cache_valid value for nginx
two differents fastcgi_cache_valid value for nginx

Time:11-25

I use fastcgi_cache in nginx and I want to use two different period of time caching for different requests.

For example:

    if ($request_uri ~* "/(api/1|api/2)")
        {
           set $no_cache 0;
           set $cache_valid 5m;
        }
    ...
    
    fastcgi_cache_valid 200 $cache_valid; // it's not work
    
    fastcgi_cache_valid 200 1m; // it's work

How i can use two different fastcgi_cache_valid time values?

CodePudding user response:

You can't use variables with the fastcgi_cache_valid directive. If your upstream API web app is under your control, you'd better make it return X-Accel-Expires: 0 HTTP header for the /api/1, /api/2 and other requests that shouldn't be cacheable. If it isn't, I think your only way is to use two different location blocks with different fastcgi_cache_valid directives.

CodePudding user response:

thankyou. I created two location sections in nginx config and set two different params/ it's working now

  • Related