# Problems getting NginX to cache

**URL:** <https://www.ruby-forum.com/t/problems-getting-nginx-to-cache/185856>\
**Category:** NGINX\
**Created:** [March 27, 2010, 1:40pm UTC](https://www.ruby-forum.com/t/problems-getting-nginx-to-cache/185856 "2010-03-27T13:40:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [March 27, 2010, 1:40pm UTC](https://www.ruby-forum.com/t/problems-getting-nginx-to-cache/185856/1 "2010-03-27T13:40:57Z")

</div>

Folks,

I’ve been trying to setup NginX as a frontend cache for a webserver.  
This is rather challenging, as the documentation is a little flakey but  
it does look like it should be fairly straight forward. The reverse  
proxing is working just fine, it just doesn’t cache anything. This is  
on version nginx version: nginx/0.7.65

I have added the following to the http {} section:

```
proxy_buffering on;
proxy_cache_valid any 10m;
proxy_cache_path /var/www/cache levels=1:2 keys_zone=my-cache:8m

```

max\_size=1000m inactive=600m;  
proxy\_temp\_path /var/www/tmp;  
proxy\_buffer\_size 4k;  
proxy\_buffers 100 8k;

The following to server {}:

```
proxy_buffering on;
proxy_store on;
proxy_store_access user:rw group:rw all:r;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;

```

And the following to location {}:

```
proxy_cache my-cache;
proxy_cache_valid 200;

```

I have enabled debugging and have a lot of logs. The relivant section  
appears to be:

2010/03/26 17:20:45 [debug] 22172#0: \*163 copy filter: “/?”  
2010/03/26 17:20:45 [debug] 22172#0: \*163 http postpone filter “/?”  
00000000006C7408  
2010/03/26 17:20:45 [debug] 22172#0: \*163 write old buf t:1 f:0  
00000000006C7138, pos 00000000006C7138, size: 279 file: 0, size: 0  
2010/03/26 17:20:45 [debug] 22172#0: \*163 write new buf t:0 f:1  
00000000006C7870, pos 00000000006C79D6, size: 1300 file: 358, size: 1300  
2010/03/26 17:20:45 [debug] 22172#0: \*163 http write filter: l:0 f:0  
s:1579  
2010/03/26 17:20:45 [debug] 22172#0: \*163 http write filter limit 0  
2010/03/26 17:20:45 [debug] 22172#0: \*163 writev: 279  
2010/03/26 17:20:45 [debug] 22172#0: \*163 sendfile: @358 1300  
2010/03/26 17:20:45 [debug] 22172#0: \*163 sendfile: 1300, @358 1300:1300  
2010/03/26 17:20:45 [debug] 22172#0: \*163 http write filter  
0000000000000000  
2010/03/26 17:20:45 [debug] 22172#0: \*163 copy filter: 0 “/?”  
2010/03/26 17:20:45 [debug] 22172#0: \*163 pipe write downstream done  
2010/03/26 17:20:45 [debug] 22172#0: \*163 event timer: 13, old:  
1269624105234, new: 1269624105236  
2010/03/26 17:20:45 [debug] 22172#0: \*163 http file cache update  
2010/03/26 17:20:45 [debug] 22172#0: \*163 http file cache rename:  
“/var/www/tmp/0000000081” to  
“/var/www/cache/8/ac/3577c9b1c200387b980a8810e0b67ac8”  
2010/03/26 17:20:45 [crit] 22172#0: \*163 chmod()  
“/var/www/tmp/0000000081” failed (2: No such file or directory) while  
reading upstream, client: 1.1.1.1, server: [www.example.net](http://www.example.net),  
request: “GET / HTTP/1.1”, upstream: “[http://1.2.3.4:80/](http://1.2.3.4:80/)”, host:  
“[www.exmaple.net:80](http://www.exmaple.net:80)”  
2010/03/26 17:20:45 [crit] 22172#0: \*163 unlink()  
“/var/www/tmp/0000000081” failed (2: No such file or directory) while  
reading upstream, client: 1.1.1.1, server: [www.example.net](http://www.example.net),  
request: “GET / HTTP/1.1”, upstream: “[http://1.2.3.4:80/](http://1.2.3.4:80/)”, host:  
“[www.exmaple.net:80](http://www.exmaple.net:80)”  
2010/03/26 17:20:45 [debug] 22172#0: \*163 http upstream exit:  
0000000000000000  
2010/03/26 17:20:45 [debug] 22172#0: \*163 finalize http upstream  
request: 0  
2010/03/26 17:20:45 [debug] 22172#0: \*163 finalize http proxy request  
2010/03/26 17:20:45 [debug] 22172#0: \*163 free rr peer 1 0

So it seems it can’t chmod or ulink the file cause it’s not there.  
There’s no indication of why this might be. Nginx quite happilly  
creates the proxy tmp directory but doesn’t appear to put anything in  
it. Even though the debug suggests that it thinks that is has.

Does anyone have any idea what is going on?

I’ve only seen on similar occurance of this on the Russian list but this  
was in Russian 🙂 Google translate suggested that they didn’t really  
bottom it out.

Mike.

---

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [March 28, 2010, 1:03am UTC](https://www.ruby-forum.com/t/problems-getting-nginx-to-cache/185856/2 "2010-03-28T01:03:53Z")

</div>

On Sat, Mar 27, 2010 at 12:40:28PM +0000, Mike wrote:

> Folks,
> 
> I’ve been trying to setup NginX as a frontend cache for a webserver.  
> This is rather challenging, as the documentation is a little flakey but  
> it does look like it should be fairly straight forward. The reverse  
> proxing is working just fine, it just doesn’t cache anything. This is  
> on version nginx version: nginx/0.7.65

Seems that the solution to this was to comment out the following two  
lines:

#proxy\_store on;  
#proxy\_store\_access user:rw group:rw all:r;

Or rather, to turn proxy\_store off. The cache appears to be caching  
quite happilly now.

Mike.

---

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [March 28, 2010, 1:33am UTC](https://www.ruby-forum.com/t/problems-getting-nginx-to-cache/185856/3 "2010-03-28T01:33:46Z")

</div>

Hello!

On Sat, Mar 27, 2010 at 12:40:28PM +0000, Mike wrote:

> I’ve been trying to setup NginX as a frontend cache for a webserver.  
> This is rather challenging, as the documentation is a little flakey but  
> it does look like it should be fairly straight forward. The reverse  
> proxing is working just fine, it just doesn’t cache anything. This is  
> on version nginx version: nginx/0.7.65

[…]

> ```
> proxy_cache my-cache;
> proxy_cache_valid 200;
> 
> ```

[…]

Directives proxy\_store and proxy\_cache can’t be used at the same  
time, while in your config proxy\_store is inherited from server  
level - so effectively you have both of them switched on in the  
location.

It’s the bug that nginx doesn’t reject such configuration as  
invalid.

Adding “proxy\_store off;” to your location with proxy\_cache (or  
just removing it from server block) will resolve your problem.

Maxim D.
