E
E
emashev2019-01-24 18:36:41
Nginx
emashev, 2019-01-24 18:36:41

Nginx not deleting cache, how to fix?

Greetings, there is a site on Bitrix - nginx + php-fpm. Static is already cached on it:

location  ~* \.(css|js|gif|png|jpg|jpeg|ico|ogg|ttf|woff|eot|otf)$ {
          error_page 404 /404.html;
          expires 30d;
        }

Requests to this site also go through the caching nginx proxy.
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=all:64m max_size=1g;
        proxy_cache_key $request_uri;
        proxy_cache_valid 5m;

So, when modifying a picture on the server, the caching proxy returns the old picture with the 304 code, even after 5 minutes. The Last-Modified header remains the same. If the request is made directly - to the nginx of Bitrix (in /etc/hosts by registering the site) - the picture is already new there. Only clearing the cache on the proxy helped. Why doesn't nginx itself clear the cache after 5 minutes?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Korobkov, 2019-01-24
@emashev

In the documentation nginx.org/en/docs/http/ngx_http_proxy_module.html#...

Parameters of caching can also be set directly in the response header. This has higher priority than setting of caching time using the directive.
parameters of caching may be set in the header fields “Expires” or “Cache-Control”.

That is your title
takes precedence over your setting
proxy_cache_valid 5m;

E
emashev, 2019-01-24
@emashev

I also thought the browser at first. I cleared my entire history, cookies and cache - it still gave the old image, changed the site address to nginx from bitrix in /etc/hosts - gives out a new one, rearranged it back - still the old one. The old and new have different Last-Modified headers. I cleared the cache on the proxy - only then issued a new one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question