Hello!

I’m trying to configure caching on nginx, I need to receive one backend request if the absenceor update cache, for this I understand you need to use the proxy_cache_lockdirective but in the absence of a cache, initially with a large number of requests, they are not blocked but are sent to the backend.What did I do wrong?

 proxy_cache_valid 200 1m;
    
proxy_cache_use_stale updating;
proxy_cache_background_update on;
proxy_cache_lock on;

proxy_cache_path/var/local/nginx/cache levels=1: 2 inactive=12h keys_zone=cache: 10m max_size=500m use_temp_path=off;
proxy_cache_key $http_host $request_uri;

1 Answers 1

The problem was solved by simply adding the directive proxy_cache_lock_timeout

proxy_cache_lock_timeout 60s;
  • So you just had requests longer than 5 seconds? – Hungry5 Oct 3 '19 at 12:55
  • Hungry5, The problem was that during load testing, most nginx requests were passed to the backend for some reason I did not understand, after adding this directive the problem was solved. – Bored Butterfly Oct 3 '19 at 12:58