S
S
Stepgor2020-11-12 16:19:53
Nginx
Stepgor, 2020-11-12 16:19:53

How to cache nginx static?

There are 2 servers, 1 - it stores statics and 2 - it takes statics from 1 and gives it to the client. How to cache statics on server 2 (let's say for an hour) and give it to the client? I tried this option, but requests to server 1 still go to each given static.

proxy_cache_path /home/admin/nginx_cache levels=1:2 keys_zone=static:10m max_size=1g;
proxy_cache_methods GET HEAD POST;

server {
    location /static/ {
        proxy_pass http://localhost:3001$request_uri;
        proxy_cache static;
        proxy_cache_valid any 10m;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-11-12
@UPSA

It was a long time ago ....
1. Run nginx with debug logs. There, it seems, you can catch messages about comparing files (checking any conditions).
2. Requests will always be. nginx has to be compared to something. Those between 1 and 2 requests will always be there.
3. Do files appear in the /home/admin/nginx_cache folder? It seems that hashes of files from static should be stored there (like the name of the file is a hash, or maybe just hashes - I don’t remember)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question