사용이 하나
(https://github.com/varnishcache/varnish-devicedetect에서 일부)이 저장
sub detectbot {
unset req.http.X-Bot-Detected;
# mobile bots
if (req.http.User-Agent ~ "\(compatible; Googlebot-Mobile/2.1; \+http://www.google.com/bot.html\)"
|| (req.http.User-Agent ~ "iPhone" && req.http.User-Agent ~ "\(compatible; Googlebot/2.1; \+http://www.google.com/bot.html")) {
set req.http.X-Bot-Detected = "mobile-bot";
}
# other bots
elsif (req.http.User-Agent ~ "(?i)(ads|google|bing|msn|yandex|baidu|ro|career|seznam|)bot"
|| req.http.User-Agent ~ "(?i)(baidu|jike|symantec)spider"
|| req.http.User-Agent ~ "(?i)scanner"
|| req.http.User-Agent ~ "(?i)(web)crawler") {
set req.http.X-Bot-Detected = "bot";
}
}
으로 감지-bot.vcl을 (당신의 광택 default.vcl과 같은 디렉토리에) 를 다음의 상단에 당신의 default.vcl는
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);
}
}
이 예에서는 요청을 다른 백엔드로 보냅니다. 설정 내용이 어떻게 작동하는지에 따라 마지막 부분을 조정해야합니다. 더 많은 예제는 https://www.varnish-cache.org/docs/4.1/users-guide/devicedetection.html을 참조하십시오.