F
F
furyon2021-03-05 04:50:09
Nginx
furyon, 2021-03-05 04:50:09

How to configure static caching in nginx?

You need to set up a server that distributes images. It should take images and cache them with http://1.2.3.4. Current config:

proxy_cache_path /var/www/my_cache levels=2:2:2 keys_zone=STATIC:100m inactive=1d;
server {
    listen 80 default_server;
    server_name _;
    location / {
        proxy_pass          http://1.2.3.4;
        proxy_buffering     on;
        proxy_cache         STATIC;
        proxy_cache_valid   200 100d;
    }
}


The problem is, if I refresh the image in the browser via ctrl+f5 , this config will follow the image to http://1.2.3.4even if it is in the cache. The same situation if I open the image in another browser.

Tried including:
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers Cache-Control;
and
proxy_hide_header Cache-Control;
proxy_hide_header Set-Cookie;


Those. the essence of the task: If the image is in the cache and the proxy_cache_valid has not expired, always return from the cache, no matter who requests it and with what headers.

Glad for any leads. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Slashchinin, 2021-03-06
@slashinin

Maybe not quite on the topic, but Varnish has similar solutions .
This is just a caching server and its work can be easily configured in tandem with nginx .
Thematic articles are here
https://ruhighload.com/varnish

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question