nginx proxy cache配置和清理

1.nginx需要编译Purge模块

2.nginx.conf 配置cache:

proxy_cache_path /home/cache/xxx levels=1:2 keys_zone=cache_xxx:1000m inactive=24h max_size=10g;

3.代理服务器配置:

记住 clear要配置在前面:

location ~ ^/jfclear(/.*) {

allow 1.1.1.1;

allow 10.0.0.0/24;

allow 127.0.0.1;

deny all;

proxy_cache_purge cache_xxx $1$is_args$args; #这个key要和缓存的key取得一样,才能通过md5找到一样的路径,删除缓存文件(根据nginx内置常量来组合)

}

location / {

cache_xxx;

proxy_cache_valid 200 304 6h;

proxy_cache_key $uri$is_args$args; #这个key很重要,cache通过key 做md5来建立目录存放缓存文件,删除也根据key来删除(根据nginx内置常量来组合)

add_header Nginx-Cache "$upstream_cache_status";

include proxy.conf;

proxy_pass http://xxx_server;

expires 6h;

}