瀏覽器緩存原理
瀏覽器緩存
HTTP協議定義的緩存機制(如:Expires;Cache-control等)
2、瀏覽器無緩存
3、客戶端有緩存
校驗過期機制
校驗是否過期 Expires、Cache-Control(max-age)
協議中Etag頭信息校驗 Etag
Last-Modified頭信息校驗 Last-Modified
5、配置語法-expires
添加 Cache-Control、Expires頭
Syntax: expires [modified] time;
expires epoch|max|off;
Default: expires off; # 靜態緩存
Context: http,server,location,if in location
location ~ .*\.(htm|html)$ { expires 24h; root /opt/app/code; }
動態緩存設置
upstream imooc { server 116.62.103.228:8001; server 116.62.103.228:8002; server 116.62.103.228:8003; } proxy_cache_path /opt/app/cache levels=1:2 keys_zone=imooc_cache:10m max_size=10g inactive=60m use_temp_path=off; server { listen 80; server_name web01.fadewalk.com; access_log /var/log/nginx/test_proxy.access.log main; location / { proxy_cache off; proxy_pass http://imooc; proxy_cache_valid 200 304 12h; proxy_cache_valid any 10m; proxy_cache_key $host$uri$is_args$args; add_header Nginx-Cache "$upstream_cache_status"; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; include proxy_params; } }
查看
304 Not Modified