nginx緩衝到期管理小結

來源:互聯網
上載者:User

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 directivesproxy_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"頭。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.