[nginx小技巧]httpheader准确显示命中状态
文章目录
nginx缓没缓存请求是我们关心的问题,把缓存状态显示在header里是个不错的选择。
方法如下:
使用$upstream_cache_status 变量
示例:add_header ADKS-Cache "$upstream_cache_status from www.front2end.com"; 变量值:
- MISS
- EXPIRED - expired, request was passed to backend
- UPDATING - expired, stale response was used due to proxy/fastcgi_cache_use_stale updating
- STALE - expired, stale response was used due to proxy/fastcgi_cache_use_stale
- HIT
效果:
相应头信息
ADKS-Cache | HIT from www.front2end.com | |||
Cache-Control | max-age=3600 | |||
Connection | keep-alive | |||
Date | Wed, 10 Oct 2012 01:41:57 GMT | |||
Etag | "0463e6df954cd1:0" | |||
Expires | Wed, 10 Oct 2012 02:41:57 GMT | |||
Last-Modified | Thu, 28 Jun 2012 06:44:12 GMT | |||
Server | nginx/1.2.4 | |||
X-Powered-By | ASP.NET |
文章作者 古道
上次更新 2012-10-10