首页 > 其他 > 详细

Nginx系列(三)——内容缓存

时间:2020-05-21 18:19:58      阅读:43      评论:0      收藏:0      [点我收藏+]

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_cache mycache;
    slice 1m;    #以1m为单位进行切片
    proxy_cache_key $host$uri$is_args$args$slice_range;    #切片命名方式?
    proxy_set_header Range $slice_range;
    proxy_http_version 1.1;
    proxy_cache_valid 200 206 1h;
    location / {
    proxy_pass http://origin:80;
    }
}


Nginx系列(三)——内容缓存

原文:https://www.cnblogs.com/biaopei/p/12932412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!