cache.conf
proxy_cache_path /data/nginx/tmpcache levels=2:2 keys_zone=two:10m loader_threshold=300
loader_files=200 max_size=200m inactive=1m;
server {
server_name cache.taohui.tech;
listen 8097;
root html/;
error_log logs/cacherr.log debug;
location /{
proxy_cache two;
proxy_cache_valid 200 1m;
add_header X-Cache-Status $upstream_cache_status;
proxy_pass http://localhost:8012;
}
}
1.
upserver.conf
server {
listen 8012;
default_type text/plain;
root html;
location / {
}
}
创建目录/data/nginx/tmpcache,第一次访问没有缓存,第二次存在缓存。缓存在1分钟后过期
2.
upserver.conf
server {
listen 8012;
default_type text/plain;
add_header X-Accel-Expires 3;
root html;
location / {
}
}
2.增加X-Accel-Expires 3;指令缓存在3s后过期
3.增加Vary *;表示都不做缓存
4.add_header Cache-Control 'max-age=3,stale-while-revalidate=3'; Cache-Control和Vary *;是一样的都不会做缓存