热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在头文件中显示nginx缓存文件的年龄-Howtodisplaytheageofannginxcachedfileinheaders

Ivesetupacachingserverforasitethroughnginx1.6.3onCentOS7,anditsconfiguredtoadd

I've set up a caching server for a site through nginx 1.6.3 on CentOS 7, and it's configured to add http headers to served files to show if said files came from the caching server (HIT, MISS, or BYPASS) like so:

我在CentOS 7上通过nginx 1.6.3为一个站点设置了一个缓存服务器,它被配置为向服务文件添加http头,以显示所述文件是否来自缓存服务器(HIT、MISS或BYPASS),如下所示:

add_header X-Cached $upstream_cache_status;

However, i'd like to see if there's a way to add a header to display the age of the cached file, as my solution has proxy_cache_valid 200 60m; set, and i'd like to check that it's respecting that setting.

但是,我想看看是否有一种方法可以添加标题来显示缓存文件的年龄,因为我的解决方案是proxy_cache_valid 20060m;集合,我想检查它是否与那个集合有关。

So what i'm looking for would be something like:

所以我要找的是:

add_header Cache-Age $upstream_cache_age;

I'm unable to find anything of the sort though, can you help?

我找不到这种东西,你能帮忙吗?

Thanks

谢谢

2 个解决方案

#1


2  

The nginx documentation is quite exhaustive — there's no variable with the direct relative age of the cached file.

nginx文档非常详尽——没有任何变量与缓存文件的直接相对年龄有关。

The best way would be to use the $upstream_http_ variable class to get the absolute age of the resource by picking up its Date header through $upsteam_http_date.

最好的方法是使用$upstream_http_变量类,通过$upsteam_http_date获取其日期头,从而获得资源的绝对年龄。

add_header X-Cache-Date $upstream_http_date;

For the semantic meaning of the Date header field in HTTP/1.1, refer to rfc7231#section-7.1.1.2, which describes it as the time of the HTTP response generation, so, basically, this should accomplish exactly what you want (especially if the backend runs with the same timecounter).

对于HTTP/1.1中的日期头字段的语义含义,请参考rfc7231# section7.1.1.2,它将它描述为HTTP响应生成的时间,因此,基本上,这应该完全实现您想要的(特别是如果后端运行时使用相同的timecounter)。

#2


0  

I spent some time attempting to solve this with the Nginx Perl module, which does not seem to have access to $upstream_http_NAME headers that would allow you to successfully calculate the current time from a timestamp header that your proxied application created during render time.

我花了一些时间尝试使用Nginx Perl模块来解决这个问题,该模块似乎无法访问$upstream_http_NAME头文件,这些头文件可以让您成功地从您的经过代理的应用程序在呈现期间创建的时间戳头中计算当前时间。

Alternatively, you could use a different caching layer architecture like Varnish Cache, which does indeed provide the Age HTTP response header:

或者,您可以使用不同的缓存层架构,如Varnish缓存,它确实提供了Age HTTP响应头:

http://book.varnish-software.com/3.0/HTTP.html#age

http://book.varnish-software.com/3.0/HTTP.html年龄


推荐阅读
author-avatar
和你在一起1979
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有