2016-11-11 7 views

답변

0

캐시 할 관련 URL이있는 머리글을 설정하고 바니시가 개체를 해시하는 방식을 변경할 수 있습니다.

sub vcl_recv { 
    ... 
    # Remove the params you don't want from the query string and set it to a 
    # temp header (Varnish does not have variables) 
    set req.http.x-cache-url = regsub(req.url,"(utm1=.*&|utm1=.*)", "") 
    ... 
} 

# Below is the default vcl_hash but swapping the req.url for req.http.x-cache-url 
sub vcl_hash { 
    hash_data(req.http.x-cache-url); 
    if (req.http.host) { 
    hash_data(req.http.host); 
    } else { 
    hash_data(server.ip); 
    } 
    return (lookup); 
} 

이렇게하면 쿼리 문자열을 그대로 유지할 수 있고 다른 매개 변수에 대해 동일한 캐시를 제공 할 수 있습니다.

당신이 PARAMS를 조작 곳 regsub이라고. 부담없이 바꿀 수 있습니다.

0

더 나은 해결책은 들어오는 URL을 다시 쓰고 불필요한 VCL을 도입하지 않는 것입니다. 이것은 또한 단지 utm_ones, 모든 Google 관련 자바 스크립트 변수 처리됩니다 :

if (req.url ~ "(\?|&)(gclid|utm_[a-z]+)=") { 
    set req.url = regsuball(req.url, "(gclid|utm_[a-z]+)=[-_A-z0-9\+\(\)%]+&?", ""); 
    set req.url = regsub(req.url, "(\?|&)$", ""); 
} 

stripping Google Analytics variables with Varnish 내 원래의 게시물에서 자세한 내용을 참조하십시오.