先看一个经典的配置,注意红色部分:
proxy_cache_path /cache levels=1:2 keys_zone=cache_pool:512minactive=1m max_size=10g;
location ~ .*\.(jpg|gif|png)$
{
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_pool;
proxy_cache_valid 200 304 2m;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://storage1;
expires 10m;
}
Cached data that are not accessed during the time specified by the inactive parameter get removed from the cache regardless of their freshness. By default,inactive is set to 10 minutes.
expires: Controls whether the response should be marked with an expiry time, and if so, what time that is.