Different cache time for different locations

Maxim Dounin mdounin at mdounin.ru
Fri Aug 31 17:08:24 UTC 2012


Hello!

On Fri, Aug 31, 2012 at 05:46:02PM +0100, Nuno Neves wrote:

> Hello,
> 
> All my requests passes in the php location to fastcgi ( location ~
> \.php$ ) and I would like to have different cache time for different
> requests.
> 
> As an example :
> 
> / -> cache time for 10 minutes
> /about -> cache time for 1 day
> /products -> cache time for 1h
> 
> Right now I have the same cache for all requests: fastcgi_cache_valid
> 200 302  10m;
> 
> How am I able to accomplish this setup?

Configure different locations to handle different requests, for 
example

   location = / {
       fastcgi_pass ...
       fastcgi_cache_valid 10m;
       ...
   }

   location = /about {
       fastcgi_pass ...
       fastcgi_cache_valid 1d;
       ...
   }

   location = /products {
       fastcgi_pass ...
       fastcgi_cache_valid 1h;
       ...
   }

Maxim Dounin



More information about the nginx mailing list