Nginx系列(三)——内容缓存
Caching Zones 定义缓存空间 proxy_cache_path /var/nginx/cache #缓存空间路径 keys_zone=CACHE:60m levels=1:2 inactive=3h #缓存时长,3小时内没有被再次请求就会被释放 max_size=20g; proxy_cache CACHE; Caching Hash Keys 使用proxy_cache_key模块 proxy_cache_key "$host$request_uri $cookie_user"; Cache Bypass 避开缓存。适用于进行troubleshooting和debug的时候 proxy_cache_bypass $http_cache_bypass; 另外还可以通过设置 proxy_cache off; 进行关闭缓存 Cache Performance 在用户端控制缓存 location ~* \.(css|js)$ { expires 1y; #1年后过期 add_header Cache-Control "public"; #配置http响应头缓存控制 } Cache Slicing 缓存切片。适用于不会变动的大文件 proxy_cache_path /tmp/mycache keys_zone=mycache:10m; server { ... proxy