# Different cache\_valid per location

**URL:** <https://www.ruby-forum.com/t/different-cache-valid-per-location/220657>\
**Category:** NGINX\
**Created:** [June 15, 2012, 12:42pm UTC](https://www.ruby-forum.com/t/different-cache-valid-per-location/220657 "2012-06-15T12:42:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [June 15, 2012, 12:42pm UTC](https://www.ruby-forum.com/t/different-cache-valid-per-location/220657/1 "2012-06-15T12:42:30Z")

</div>

Hi,

I’m trying to find the correct way to have different cache times per  
location.  
The problem I have is that all locations are redirected using try\_files  
to the same file and then to fastcgi.

I was thinking about something like this, but it doesn’t work:

fastcgi\_cache\_path /var/cache/nginx/one levels=1:2  
keys\_zone=one:500m;

server {

```
location /a {
  fastcgi_cache_valid 200 15m;
  try_files $uri $uri/ /index.php;
}

location /b {
  fastcgi_cache_valid 200 60m;
  try_files $uri $uri/ /index.php;
}

```

## PHP

location ~ .php$ {  
…  
fastcgi\_cache one;  
fastcgi\_cache\_use\_stale error timeout invalid\_header http\_500;  
…  
}  
}

How can I archive this?

Thanks

NN

Posted at Nginx Forum:

> **[Different cache\_valid per location](https://forum.nginx.org/read.php?2,227557,227557#msg-227557)**
>
> Hi, I'm trying to find the correct way to have different cache times per location. The problem I have is that all locations are redirected using try\_files to the same file and then to fastcgi. I was thinking about something like this, but it doesn't...
