Nginx 缓存命中率
# 在http头部显示命中方式 location ~* ^.*\.(js|ico|gif|jpg|jpeg|png)$ { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 180; proxy_send_timeout 180; proxy_read_timeout 180; proxy_buffer_size 128k; proxy_buffers 4 128k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; proxy_cache cache; proxy_cache_valid 200 304 1h; proxy_cache_valid 404 1m; proxy_cache_key $host$uri$is_args$args; add_header Nginx-Cache "$upstream_cache_status"; proxy_pass http://backend; }
log_format main '$remote_addr - $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" "$request_body" ' '"$http_user_agent" "$http_x_forwarded_for"' 'cache_status:$upstream_cache_status upstream:$upstream_addr ' 'response_time: $request_time response_time: $request_time host: $host'; #日志缓存命中率: MISS : 未命中,请求被传送到后台处理 HIT: 缓存命中 EXPIRED: 缓存已经过期,请求被传送到后台处理 UPDATING: 正在更新缓存,将使用旧的应答 STALE: 后端得到过期的应答