N
N
NubasLol2021-08-19 19:06:54
Nginx
NubasLol, 2021-08-19 19:06:54

How to configure nginx cache correctly?

I just can’t understand, I sort of set up the image cache on the site, but sometimes in X-Cache instead of HIT comes EXPIRED. Although the cache definitely could not become outdated literally in a day, and it is on the server in the cache folder. This heading is deceiving me, or I have configured something wrong and there are subtleties. Maybe some other headings need to be added?

location / {
    add_header X-Cache $upstream_cache_status;
        proxy_cache imgproxy;
        proxy_cache_valid 200 30d;

        access_log off;
        allow all;
        expires 1M;

    proxy_pass         http://imgproxy:8080;
    proxy_redirect     off;
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Host $server_name;
  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question