使用nginx缓存机制
话不多说,上代码
- 添加缓存头,缓存到浏览器
server {
listen 88;
server_name geoserver;
location {
// 添加缓存头 设置缓存时间,目前是8分钟
add_header Cache-Control max-age=640;
proxy_pass http://127.0.0:8080;
}
}
2.设置缓存文件 nginx缓存
proxy_cache_path /data/nginx/cache keys_zone=one:10m;
location /cache{
proxy_cache my_cache;
proxy_cache_key $uri$is_args$args;
#缓存的有效期 10m
proxy_cache_valid any 10m;
proxy_cache_min_use 1;
#添加缓存命中状态 $upstream_cache_status
add_header Nginx-Cache $upstrean_cache_status;
proxy_pass http://127.0.0:8080/;
}
详细参数可见
https://zhuanlan.zhihu.com/p/428788115
欢迎有其他方法的大佬多多指教