缓存服务
作用:减少后端的压力
服务端缓存 服务端缓存
Nginx缓存 代理缓存
客户端缓存
proxy_cache配置语法
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_files=number]
[loader_sleep=time] [loader_threshold=time] [purger_sleep=time]
[puger_threshold=time];
Default:–
Context:http
syntax: proxy_cache zone | off;
Default: proxy_cache off;
Context: http,server,location;
配置语法-缓存过期周期
Syntax: proxy_cache_valid [code …] time;
Default: –
Context: http,server,location;
配置语法-缓存的维度
Syntax: proxy_cache_key string;
Default: proxy_cache_key $scheme$proxy_host$request_uri;
Context: http,server,location
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;
location / {
#proxy_cache off;
proxy_cache imooc_cache;
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;
}
如何清理指定的缓存
方式一、rm -rf 缓存目录内容
方式二、第三方扩展模块ngx_cache_purge
如和让部分页面不缓存
Syntax: proxy_no_cache string …,
Default: –
Context: http,server,location
if($request_uri ~ ^/(url3|login|register|password/reset)){
set $cookie_nocache 1;
}
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 off;
proxy_cache imooc_cache;
proxy_pass http://imooc;
proxy_cache_valid 200 304 12h;
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”;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
include proxy_params;
}
大文件分片请求 http_slice_module
Syntax: slice size;
Default: slice 0;
Context: http,server,location;
缓存服务
netstat -luntp | grep 800
动态缓存
最新推荐文章于 2023-09-05 09:30:00 发布