常见Nginx的中间件架构(四)

#Nginx缓存服务
#配置语法
#定义
Syntax: proxy_cache_path path [levels=levels]
[use_temp_path = on|off] keys_zone=name:size [inactive=time]
[max_size=size] [manager_files=number] [manager_sleep=time]
[manager_threshold=time][loader_file=number]
[loader_sleep=time][loader_threshold=time][purger=on|off]
[purger_file=number][purger_sleep=time]
[purger_threshold=time];
Default : ——
Context:http

#使用
Syntax: proxy_cache zone  on|off;
Default : proxy_cache off
Context:http,server,location

#缓存过期周期
Syntax: proxy_cache_valid [code...] time;
Default : proxy_cache off
Context:http,server,location

#缓存维度
Syntax: proxy_cache_key string;
Default : proxy_cache_key $scheme$proxy_host$request_uri;
Context:http,server,location


#例:
#                  存放临时缓存文件  按2层目录分级 开启zone空间名字:大小  最大10g  60分钟之内无访问删除  存放临时文件关闭
#proxy_cache_path /opt/app/cache levels=1:2 keys_zone=imooc_cache:10m max_size=10g inactive=60m use_temp_path=off;
# location / {
#       proxy_cache imooc_cache;
#                         状态200、304的周期是12h
#       proxy_cache_valid 200 304 12h;
#                         其他状态10m
#       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;
#    }

#部分页面不缓存
Syntax: proxy_no_cache string;
Default : ——
Context:http,server,location
#例:
#if($request_uri ~ ^/(url3|login|register|password\/reset)){
#    set $cookie_nocache 1;
#}
# location / {
#       proxy_cache imooc_cache;
#                         状态200、304的周期是12h
#       proxy_cache_valid 200 304 12h;
#                         其他状态10m
#       proxy_cache_valid any 10m;
#       proxy_cache_key $host$uri$is_args$args;
#        proxy_no_cache $cookie_nocache $arg_nocache $arg_comment;
#        proxy_no_cache $http_pragma $http_authorization;
#                                返回头可以看出是否命中
#       add_header  Nginx-Cache "$upstream_cache_status";  
#       
#       include proxy_params;
#    }


#大文件分片请求
#切割成size片
Syntax: slice size;
Default : slice 0;
Context:http,server,location
 

猜你喜欢

转载自blog.csdn.net/SZStudy/article/details/83417021