why is proxy_cache_lock not working?

Maxim Dounin mdounin at mdounin.ru
Fri Nov 17 14:54:42 UTC 2017


Hello!

On Fri, Nov 17, 2017 at 01:49:45AM -0500, edanic0017 wrote:

[...]

> Below are the parts of the nginx configuration
> 
> 
> proxy_cache_path    /tmp/nginx/cache             
>                     levels=1:2                            
>                     keys_zone=my_cache:1m       
>                     max_size=10g                  
>                     inactive=30s                  
>                     use_temp_path=off;            
> 
>     location ~*\.(ts)$ {
> 
>              ##### Proxy cache settings
> 
>              proxy_http_version 1.1;
>              proxy_cache my_cache;
>              proxy_cache_revalidate on;
>              proxy_cache_key $uri;
>              proxy_cache_use_stale updating;
>              proxy_cache_valid any 1m;
>              proxy_cache_min_uses 1;
>              proxy_cache_lock on;
>              proxy_cache_lock_age 5s;
>              proxy_cache_lock_timeout 1h;
>              proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
>              proxy_ignore_headers Set-Cookie;
> 
> 
>                 proxy_pass http://192.168.2.225:8080;
>     }
> 
> 
> Even with proxy_cache_lock on, the original server is getting hit on every
> miss request per the logs below.
> 
> nginx access logs:
> 
> HOST82 - MISS [17/Nov/2017:00:22:03 -0600] "GET
> profile1/76861/HD_profile1_00001.ts HTTP/1.1" 206 262144 "-" "Roku/DVP-8.0
> (298.00E04108A)" "-"
> HOST225 - MISS [17/Nov/2017:00:22:04 -0600] "GET
> profile1/76861/HD_profile1_00001.ts HTTP/1.1" 206 262144 "-" "Roku/DVP-8.0
> (508.00E03138A)" "-"
> HOST187 - MISS [17/Nov/2017:00:22:05 -0600] "GET
> profile1/76861/HD_profile1_00001.ts HTTP/1.1" 200 4696992 "-" "Roku/DVP-7.70
> (047.70E04135A)" "-"
> HOST125 - MISS [17/Nov/2017:00:22:06 -0600] "GET
> profile1/76861/HD_profile1_00001.ts HTTP/1.1" 206 262144 "-" "Roku/DVP-8.0
> (248.00E04108A)" "-"
> HOST80 - MISS [17/Nov/2017:00:22:08 -0600] "GET
> profile1/76861/HD_profile1_00001.ts HTTP/1.1" 206 262144 "-" "Roku/DVP-8.0
> (288.00E04108A)" "-"

Unless the response takes many seconds (unlikely for a 5 megabyte 
file, use $upstream_response_time to be sure), MISS in both 
00:22:03 and 00:22:08 lines indicate that the response is not 
cached at all.

Given that you already ignore X-Accel-Expires, Expires, 
Cache-Controli, and Set-Cookie headers in your configuration, the 
remaining header which may affect caching is Vary.  Check if it's 
in the responses.

Also, caching might not work if the response is incorrect (number 
of bytes returned does not match Content-Length, or a connection 
is closed with an error), or nginx can't write to cache directory.  
Check your error log for possible errors reported.

There is also a small possibility that caching works, but 
particular items are almost immediately removed due to lack of 
resources - given your cache is configured with only 1m keys zone, 
it is only capable of storing about 8k items.  I don't think this 
is the case though.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list