[英]Detect device in varnish and no cache
I have an ipad app which shows a few of my wordpress posts.the site has varnish enabled.i send a custom http.User-Agent for app pages so that a few of the desktop contents does not show in app like header and footer because my app has both. 我有一个ipad应用程序,其中显示了一些我的wordpress帖子。该站点已启用清漆。我为应用程序页面发送了一个自定义的http.User-Agent,因此一些桌面内容不会在应用程序中显示,例如页眉和页脚,因为我的应用程序兼有。 So what happens is when a user visits through desktop then it is cached in varnish and when another user checks the same page using app he is getting the desktop version. 因此,当用户访问桌面时将其缓存在清漆中,而当另一个用户使用应用程序检查同一页面时,他将获得桌面版本。 I tried below in my default vcl. 我在下面的默认vcl中尝试过。
### do not cache these files:
##never cache the admin pages, or the server-status page
if (req.url ~ "wp-(admin|login)" || req.http.Content-Type ~ "multipart/form-data" || req.http.User-Agent ~ "IPAD_APP" )
{
set req.backend_hint = master;
return(pass);
}
IPAD_APP is my custom agent this did not help.May I know weather this is correct aor is there any other aproach to display different content for desktop and app version. IPAD_APP是我的自定义代理,这无济于事。请问我这是否正确,或者是否还有其他方法可以针对台式机和应用程序版本显示不同的内容。
The direct problem you are having is that the desktop version is cached, so that's what the mobile people will see. 您直接遇到的问题是台式机版本已缓存,因此移动人员将看到这些内容。 You can update the vcl_hash function to take into account whether it is the desktop or iPad (or any number of different device types might have). 您可以更新vcl_hash函数以考虑它是台式机还是iPad(或可能具有任何数量的不同设备类型)。
One option: 一种选择:
sub vcl_recv {
set req.http.X-DeviceType = "desktop";
if (req.http.User-Agent ~ "IPAD_APP") {
set req.http.X-DeviceType = "ipad_app";
}
}
sub vcl_hash {
hash_data(req.http.X-DeviceType);
}
This ends up being a light version of sending a "Vary: User-Agent" from the origin Wordpress. 最后,这是从原始Wordpress发送“ Vary:User-Agent”的简化版本。 The problem with the approach I've outlined is that in order to do a PURGE you would need to ensure that you pass each User-Agent in turn. 我概述的方法存在的问题是,要进行PURGE,您需要确保依次传递每个User-Agent。 If you are sending low-ish TTLs on your cache, then that won't be a problem however. 如果您要在缓存上发送低位TTL,那么这将不是问题。 A BAN will solve that as well. BAN也可以解决该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.