E
E
Evgeny Sheleg2013-01-10 23:08:41
Nginx
Evgeny Sheleg, 2013-01-10 23:08:41

Image caching

Hello. Please help me to implement this task:

There is this: You

location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|wav|bmp|rtf|js)$ { expires 4w; root /var/www/public_html; }
need to add a cache to it.
proxy_intercept_errors on; proxy_cache STATIC; proxy_cache_min_uses 5; proxy_cache_valid 1d; proxy_ignore_client_abort on; proxy_temp_path /tmp; proxy_cache_use_stale updating;
When requesting a picture, he searched in the cache folder, and if not there, he gave it with “root /var/www/public_html”.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
magic4x, 2013-01-11
@magic4x

It's a pretty common practice, I've done it too. However, I was told that modern fs effectively cache frequently requested files, besides, when changing the original, you do not have to smoke a copy from the cache.
If you don't have OpenVZ, don't worry and let fs do its job.

A
avalak, 2013-01-10
@avalak

The cache is not needed here. At all. Or explain why you need it (what you want to achieve with this).

    ## Serve static
    ## root укажите, если надо
    ## такая регулярка лучше
    location ~* \.(?:js|css|png|jpe?g|gif|ico|htc)$ {
        expires max;
        access_log off;
        log_not_found off;
    }

E
Evgeny Sheleg, 2013-01-11
@Duti_Fruti

And another question. Who faced, tell me how best to implement.
Let's say there is another server with the same config:
location ~* \.(?:js|css|png|jpe?g|gif|ico|htc)$
Which takes pictures from the folder and distributes them, but if it is not there, it returns from the first server and puts it in this folder (but under a normal name, not md5)
Interested in the possibility of implementation only using Nginx, without rsync or other scripts.

V
VBart, 2013-01-11
@VBart

Leave it to the kernel to do its job, it knows best. The difference compared to the user-level cache on tmpfs may or may not be negative.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question