2016-06-02 2 views
1

내 사이트의 모바일 및 데스크톱 버전을 캐싱하고 https://github.com/varnishcache/varnish-devicedetect을 사용하여 사용자 에이전트 문자열에 따라 올바른 것을 표시하기 위해 바니시를 사용하고 있습니다. 그러나 https://www.google.com/webmasters/tools/mobile-friendly/으로 사이트를 테스트 할 때 데스크톱 사이트를 얻습니다. varnish-devicedetect를 포크하고 사이트를 방문 할 때 Google이 사용하는 사용자 에이전트를 추가하는 것이 합리적입니까? 아니면 더 잘 작동하는 다른 솔루션이 있습니까?Varnish는 Google 모바일 테스터 용 데스크톱 사이트를 렌더링합니다.

사이트가 반응 형이지만 현재는 옵션이 아니라면 문제가되지 않는다는 것을 알고 있습니다.

답변

1

사용이 하나

(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을 참조하십시오.

관련 문제