# Problem with proxy cache misses

**URL:** <https://www.ruby-forum.com/t/problem-with-proxy-cache-misses/244169>\
**Category:** NGINX\
**Created:** [February 29, 2016, 8:03pm UTC](https://www.ruby-forum.com/t/problem-with-proxy-cache-misses/244169 "2016-02-29T20:03:23Z")\
**Posts on this page:** 5\
**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:** [February 29, 2016, 8:03pm UTC](https://www.ruby-forum.com/t/problem-with-proxy-cache-misses/244169/1 "2016-02-29T20:03:23Z")

</div>

Hello! I’m testing out a new configuration and there are two issues with  
the proxy cacheing feature I’m getting stuck on.

1. Everything is a cache miss, and I’m not sure why:

My cache config (anonymized):

…  
proxy\_cache\_path /var/www/test\_cache levels=2:2 keys\_zone=TEST:32m  
inactive=365d max\_size=16g loader\_files=256;  
…  
upstream haproxy {  
server 127.0.0.1:8080;  
keepalive 256;  
}  
…  
location ~ “^/[W][A-Za-z0-9\_-]{7,13}$” {  
limit\_except GET {  
deny all;  
}  
proxy\_http\_version 1.1;  
proxy\_set\_header Connection “Close”; # Disable Keepalives  
proxy\_set\_header Host “[www.testhost.com](http://www.testhost.com)”; # Upstream requires this  
value  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header X-Forwarded-Proto https;  
proxy\_cache TEST;  
proxy\_cache\_key $uri;  
proxy\_cache\_valid 301 365d;  
proxy\_cache\_valid 302 1d;  
proxy\_cache\_lock on;  
proxy\_buffering off;  
proxy\_pass [http://haproxy](http://haproxy);  
}  
…

A sample response coming back from the upstream (captured with  
wireshark)

HTTP/1.1 301 Moved Permanently  
Date: Mon, 29 Feb 2016 18:16:02 GMT  
Content-Type: text/html  
Transfer-Encoding: chunked  
Connection: close  
P3P: CP=“some text”  
X-Frame-Options: deny  
Location: [http://some.test.url/](http://some.test.url/)

0

The cache directory is owned by the nginx user, perms 0700.

I’m expecting the 301 in the example above to be cached for a year, but  
nothing is created under /var/www/test\_cache, and subsequent requests  
for  
the same resources are also cache misses.

1. For each URL which doesn’t match any of the location blocks, I am  
seeing  
an error in the log file:

2016/02/29 13:55:20 [error] 19524#0: \*1509121054 open()  
“/var/www/html/W4ud7y1k4jjbj” failed (2: No such file or directory),  
client: a.b.c.d, server:test.com, request: “HEAD /W4ud7y1k4jjbj  
HTTP/1.1”,  
host: “[test.com](http://test.com)”

There is a “root /var/www/html” defined in the http block, although  
there  
is only one specific location which uses it:

```
location = /apple-app-site-association {
  default_type application/pkcs7-mime;
  break;
}

```

And the final location block in my server config is:

```
location = / {
  rewrite ^ https://www.someother.test.com/ permanent;
  break;
}

```

So my expectation is that since the request matches none of the location  
blocks, nginx will just issue a 404 response. However from the error  
log,  
it looks like it is trying the root directory first before issuing the  
404.  
Is there some way to prevent that?

---

<div class="post-metadata">

**Author:** ![CJ\_Ess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@CJ\_Ess](https://www.ruby-forum.com/u/CJ_Ess)\
**Post date:** [February 29, 2016, 8:16pm UTC](https://www.ruby-forum.com/t/problem-with-proxy-cache-misses/244169/2 "2016-02-29T20:16:15Z")

</div>

Look at your proxy cache path… (proxy\_cache\_path  
/var/www/test\_cache)Are you sure the path exists and had proper  
perms/ownership?

Payam

---

<div class="post-metadata">

**Author:** ![CJ\_Ess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@CJ\_Ess](https://www.ruby-forum.com/u/CJ_Ess)\
**Post date:** [February 29, 2016, 9:21pm UTC](https://www.ruby-forum.com/t/problem-with-proxy-cache-misses/244169/3 "2016-02-29T21:21:05Z")

</div>

Yes, it does exist:

stat /var/www/test\_cache

File: `/var/www/test\_cache’  
Size: 4096 Blocks: 8 IO Block: 4096 directory  
Device: 802h/2050d Inode: 22195081 Links: 2  
Access: (0700/drwx------) Uid: ( 497/ nginx) Gid: ( 0/ root)  
Access: 2016-02-29 15:14:19.271701729 -0500  
Modify: 2016-02-29 15:14:15.894687178 -0500  
Change: 2016-02-29 15:14:15.894687178 -0500

I did an su to nginx and touched a file in the directory and removed it  
without issue. I did an nginx reload and I didn’t see any warnings or  
errors regarding permissions in the error log.

---

<div class="post-metadata">

**Author:** ![CJ\_Ess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@CJ\_Ess](https://www.ruby-forum.com/u/CJ_Ess)\
**Post date:** [February 29, 2016, 9:32pm UTC](https://www.ruby-forum.com/t/problem-with-proxy-cache-misses/244169/4 "2016-02-29T21:32:46Z")

</div>

The location = / is a exactly match.  
To execute a “catch all” returning a 404 you can do a

location / {  
return 404;  
}

---

<div class="post-metadata">

**Author:** ![CJ\_Ess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@CJ\_Ess](https://www.ruby-forum.com/u/CJ_Ess)\
**Post date:** [February 29, 2016, 10:49pm UTC](https://www.ruby-forum.com/t/problem-with-proxy-cache-misses/244169/5 "2016-02-29T22:49:53Z")

</div>

The catch-all entry works and don’t conflict with the = /. That solves  
my  
second problem, thank you!

On Mon, Feb 29, 2016 at 3:32 PM, Wandenberg P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
