# Proxy\_cache is not working

**URL:** <https://www.ruby-forum.com/t/proxy-cache-is-not-working/244638>\
**Category:** NGINX\
**Created:** [May 17, 2016, 2:39pm UTC](https://www.ruby-forum.com/t/proxy-cache-is-not-working/244638 "2016-05-17T14:39:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [May 17, 2016, 2:39pm UTC](https://www.ruby-forum.com/t/proxy-cache-is-not-working/244638/1 "2016-05-17T14:39:18Z")

</div>

nginx is not caching anything. Every request that’s supposed to be  
cached  
has “http cacheable: 0” in debug log.

Test request is a static page with headers like those

\< HTTP/1.1 200 OK  
\< Date: Tue, 17 May 2016 12:23:36 GMT  
\< Server: Apache/2.2.15 (CentOS)  
\< X-Powered-By: PHP/5.5.32  
\< Content-Length: 5  
\< Connection: close  
\< Content-Type: text/html; charset=UTF-8

Can you please suggest anything?

Posted at Nginx Forum:

> **[proxy\_cache is not working](https://forum.nginx.org/read.php?2,266939,266939#msg-266939)**
>
> nginx is not caching anything. Every request that's supposed to be cached has "http cacheable: 0" in debug log. Test request is a static page with headers like those \< HTTP/1.1 200 OK \< Date: Tue, 17 May 2016 12:23:36 GMT \< Server:...

---

<div class="post-metadata">

**Author:** ![reaper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@reaper](https://www.ruby-forum.com/u/reaper)\
**Post date:** [May 17, 2016, 2:49pm UTC](https://www.ruby-forum.com/t/proxy-cache-is-not-working/244638/2 "2016-05-17T14:49:49Z")

</div>

Hello!

On Tue, May 17, 2016 at 08:39:00AM -0400, reaper wrote:

> \< Connection: close  
> \< Content-Type: text/html; charset=UTF-8
> 
> Can you please suggest anything?

You need to configure proxy\_cache\_valid for nginx to cache such a  
response, see [Module ngx\_http\_proxy\_module](http://nginx.org/r/proxy_cache_valid).

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![reaper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@reaper](https://www.ruby-forum.com/u/reaper)\
**Post date:** [May 17, 2016, 3:11pm UTC](https://www.ruby-forum.com/t/proxy-cache-is-not-working/244638/3 "2016-05-17T15:11:26Z")

</div>

It was already set but apparently wasn’t being used.

location /static/ {  
try\_files $uri @apache-cache;  
proxy\_cache\_valid 5m;  
}

location @apache-cache {  
…  
proxy\_ignore\_headers Set-Cookie Expires Cache-Control;  
proxy\_hide\_header Set-Cookie;

```
internal;

```

}

Moved this directive to second location and now it’s all fine.

Thanks!

Posted at Nginx Forum:

> **[Re: proxy\_cache is not working](https://forum.nginx.org/read.php?2,266939,266942#msg-266942)**
>
> nginx is not caching anything. Every request that's supposed to be cached has "http cacheable: 0" in debug log. Test request is a static page with headers like those \< HTTP/1.1 200 OK \< Date: Tue, 17 May 2016 12:23:36 GMT \< Server:...
