nginx 场景实践05 - 缓存服务 proxy_cache

缓存服务

proxy_cache配置语法

upstream stark {
        server 101.200.87.138:8001;
        server 101.200.87.138:8002;
        server 101.200.87.138:8003;
}

proxy_cache_path /opt/app/cache levels=1:2 keys_zone=stark_cache:10m max_size=10g inactive=60m use_temp_path=off;


location / {
	proxy_cache stark_cache; ### path中keys_zone的值
	proxy_pass http://stark;
	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_zone  zone | off   ## 缓存空间
http,server,location

proxy_cache_valid  [code]time # 缓存周日设置

proxy_cache_key $host$uri$is_args$args; #缓存的维度
http,server,location

分片请求 ( version > 1.9 )

slice size:
http,server,location

分片请求的优点:每个子请求收到的数据都会形成独立的文件,一个请求断了,其他不受影响。

动静分离

为什么要进行动静分离?减少不必要的请求消耗,减少请求延时。

当动态网站接口发生错误的时候,静态资源可以正常显示。

upstream java_api {
	server 101.200.87.138:8001;
}

location ~ \.jsp$ {
	proxy_pass http://java_api;
	index index.html index.htm
}
发布了98 篇原创文章 · 获赞 185 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/xuezhiwu001/article/details/97620716
今日推荐