歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> nginx緩存過期管理小結

nginx緩存過期管理小結

日期:2017/3/1 16:26:32   编辑:關於Linux
nginx緩存過期管理小結 先看一個經典的配置: 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. (被緩存的數據如果在inactive參數指定的時間內未被訪問,就會被從緩存中移除,不論它是否是剛產生的。inactive的默認值是10分鐘) Sets caching time for different response codes. For example, the following directives proxy_cache_valid 200 302 10m; proxy_cache_valid 404 1m; set 10 minutes of caching for responses with codes 200 and 302, and 1 minute for responses with code 404. expires: Controls whether the response should be marked with an expiry time, and if so, what time that is. 這裡總結下: inactive的時間表示一個文件在指定時間內沒有被訪問過,就從存儲系統中移除,不管你proxy_cache_valid裡設置的時間是多少。而proxy_cache_valid在保證inactive時間內被訪問過的前提下,最長的可用時間。proxy_cache_valid定義的其實是一個絕對過期時間(第一次緩存的時間+配置的緩存時間),到了這個點,對象就被認為是過期,然後去後端重取數據,盡管它被訪問的很頻繁(即所謂的inactive時間內)。expires呢,它不在這個過期控制體系內,它用在發給客戶端的響應中,添加"Expires"頭。
Copyright © Linux教程網 All Rights Reserved