本文将基于windows,使用Nginx实现http缓存功能。
注:本文基于前述基础知识,如需要查看,请点这里
1.nginx.conf配置如下:
proxy_cache_path F:\cache levels=1:2 keys_zone=demo_cache:50m inactive=10m max_size=1g;
upstream tomcats_cache{
least_conn;
server localhost:8051 weight=2 max_fails=3 fail_timeout=15;
}
server{
listen 8050;
server_name localhost;
location / {
proxy_pass http://tomcats_cache;
proxy_cache demo_cache;
proxy_cache_key $host$uri$is_args$args;
#定义200、304类型返回值的超时时间
proxy_cache_valid 200 304 1m;
#把缓存命中状态写入请求头
add_header X-Proxy-Cache $upstream_cache_status;
}
}
2.http缓存参数解析