Varnish正在为google mobile tester呈现桌面站点
我正在使用Varnish缓存我的站点的移动和桌面版本,然后根据用户代理字符串显示正确的版本。但是,当测试网站与我得到的桌面网站。使用varnish devicedetect并添加google访问该网站时使用的用户代理是否有意义?还是有其他更好的解决方案 我知道,如果网站能够响应,这不会是一个问题,但现在这不是一个选项。使用此选项: (来自的子集) 将其另存为detect-bot.vcl(与varnish default.vcl位于同一目录中) 然后在default.vcl的顶部Varnish正在为google mobile tester呈现桌面站点,mobile,varnish,Mobile,Varnish,我正在使用Varnish缓存我的站点的移动和桌面版本,然后根据用户代理字符串显示正确的版本。但是,当测试网站与我得到的桌面网站。使用varnish devicedetect并添加google访问该网站时使用的用户代理是否有意义?还是有其他更好的解决方案 我知道,如果网站能够响应,这不会是一个问题,但现在这不是一个选项。使用此选项: (来自的子集) 将其另存为detect-bot.vcl(与varnish default.vcl位于同一目录中) 然后在default.vcl的顶部 include
include "detect-bot.vcl";
然后在.vcl中添加以下部分
backend mobile {
.host = "10.0.0.1";
.port = "80";
}
sub vcl_recv {
# add a header "X-Bot-Detected" when this request was done by a bot
call detectbot;
}
sub vcl_recv {
# call some detection engine
if (req.http.X-UA-Device ~ "^mobile-bot" ) {
set req.backend = mobile;
}
}
sub vcl_hash {
if (req.http.X-UA-Device) {
hash_data(req.http.X-UA-Device);
}
}
本例将请求发送到另一个后端。根据你的设置,你需要调整最后一部分。有关更多示例,请参见
backend mobile {
.host = "10.0.0.1";
.port = "80";
}
sub vcl_recv {
# add a header "X-Bot-Detected" when this request was done by a bot
call detectbot;
}
sub vcl_recv {
# call some detection engine
if (req.http.X-UA-Device ~ "^mobile-bot" ) {
set req.backend = mobile;
}
}
sub vcl_hash {
if (req.http.X-UA-Device) {
hash_data(req.http.X-UA-Device);
}
}