# Proxy cache doesn't work in regex location?

**URL:** <https://www.ruby-forum.com/t/proxy-cache-doesnt-work-in-regex-location/202393>\
**Category:** NGINX\
**Created:** [January 28, 2011, 5:14am UTC](https://www.ruby-forum.com/t/proxy-cache-doesnt-work-in-regex-location/202393 "2011-01-28T05:14:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [January 28, 2011, 5:14am UTC](https://www.ruby-forum.com/t/proxy-cache-doesnt-work-in-regex-location/202393/1 "2011-01-28T05:14:02Z")

</div>

Hello,

I have the following two blocks:

```
location ~* \.atom$ {
    proxy_pass http://thin_projects_cluster;
    proxy_cache projects;
    proxy_cache_valid 200 10m;
    proxy_cache_use_stale off;
    #return 404;
}

location / {
    proxy_pass http://thin_projects_cluster;
    #proxy_cache projects;
    #proxy_cache_valid 200 10m;
    #proxy_cache_use_stale off;
}

```

If I comment out everything in the top block and uncomment the “return  
404” then I get 404 errors when accessing URLs ending in .atom, so I  
know that that regex is successfully matching some of my content.

That said, the problem I have is that the cache is not working for the  
top block, but if I comment the cache statements in the top block and  
uncomment the cache statements in the bottom block, the cache starts  
populating as expected. I can’t figure out what the difference is.

Does anyone know what might be going on?

Thanks,  
Jeff

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [January 28, 2011, 5:59am UTC](https://www.ruby-forum.com/t/proxy-cache-doesnt-work-in-regex-location/202393/2 "2011-01-28T05:59:05Z")

</div>

On 01/27/2011 11:12 PM, Jeff M. wrote:

> ```
> }
> 
> ```
> 
> know that that regex is successfully matching some of my content.
> 
> That said, the problem I have is that the cache is not working for the  
> top block, but if I comment the cache statements in the top block and  
> uncomment the cache statements in the bottom block, the cache starts  
> populating as expected. I can’t figure out what the difference is.
> 
> Does anyone know what might be going on?

In what I’m guessing is a similar scenario, I also didn’t get caching  
working when using try\_files to send to a location like @cluster, and  
then having those proxy\_cache directives at location @cluster.

Does proxy\_cache only work for explicitly defined locations?

Thanks,  
Jeff

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [April 8, 2011, 4:32pm UTC](https://www.ruby-forum.com/t/proxy-cache-doesnt-work-in-regex-location/202393/3 "2011-04-08T16:32:35Z")

</div>

You ever get a solution Jeff?

I’ve come accross the same problem when trying to cache anything with a  
.html extension - proxy\_cache not liking the location / regex

🙂

Posted at Nginx Forum:

> **[Re: Proxy cache doesn't work in regex location?](https://forum.nginx.org/read.php?2,170307,189430#msg-189430)**
>
> Hello, I have the following two blocks: location ~\* \\.atom$ { proxy\_pass http://thin\_projects\_cluster; proxy\_cache projects; proxy\_cache\_valid 200 10m; proxy\_cache\_use\_stale off; #return 404;

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [April 8, 2011, 6:00pm UTC](https://www.ruby-forum.com/t/proxy-cache-doesnt-work-in-regex-location/202393/4 "2011-04-08T18:00:15Z")

</div>

Hello!

On Fri, Apr 08, 2011 at 10:32:10AM -0400, andrewsuk wrote:

> You ever get a solution Jeff?
> 
> I’ve come accross the same problem when trying to cache anything with a  
> .html extension - proxy\_cache not liking the location / regex
> 
> 🙂

The solution is to carefully check headers returned by backend.

The following may/will disable cache unless ignored with  
proxy\_ignore\_headers directive: X-Accel-Expires, Expires,  
Cache-Control, Set-Cookie.

Maxim D.
