2014-10-24 2 views
0

서버 Apache/2.4.10 앞에 varnish-3.0.5 인스턴스를 실행했습니다. 동일한 Ubuntu 12.04.4 기기에서 둘 다. Varnish 서버는 이미 캐시에 페이지가 있어도 일부 요청을 백엔드 서버로 무작위로 전달합니다.무작위로 요청을 백엔드로 전송합니다.

나는 간단한 요청을 수행 할 때 가끔

Accept-Ranges: bytes 
Age: 5973 
Cache-Control: private, no-cache, no-store, must-revalidate 
Connection: keep-alive 
Content-Encoding: gzip 
Content-Length: 10015 
Content-Type: text/html; charset=utf-8 
Date: Fri, 24 Oct 2014 15:26:35 GMT 
Expires: -1 
Last-Modified: Fri, 24 Oct 2014 13:47:02 GMT 
Server: Apache 
Vary: Accept-Encoding 
Via: 1.1 varnish 
X-Varnish: 10531909 10507062 

그리고 (더 자주) 아파치에서 직접 응답 :

Cache-Control: no-cache 
Connection: keep-alive 
Content-Encoding: gzip 
Content-Length: 10015 
Content-Type: text/html; charset=utf-8 
Date: Fri, 24 Oct 2014 15:28:00 GMT 
Expires: Thu, 19 Nov 1981 08:52:00 GMT 
Last-Modified: Fri, 24 Oct 2014 15:28:00 GMT 
Server: Apache 
Set-Cookie: [truncated] 
Vary: Accept-Encoding 

GET http://www.example.com/ 
Accept: */* 
Accept-Encoding: gzip, deflate 
Host: www.example.com 
User-Agent: runscope/0.1 

가 가끔 캐시에서 올바른 응답을받을를

아파치에서 몇 가지 응답을 직접 받기 때문에 아이템이 여전히 캐시에 있다고 확신합니다. Age 헤더에 이전의 Varnish 대답보다 높은 번호가 들어있는 Varnish의 응답.

내 VCL 파일 :

# Default backend definition. Set this to point to your content server. 
backend default { 
    .host = "127.0.0.1"; 
    .port = "8080"; 
} 

# List of IPs allowed to erase things from cache 
acl purge { 
     "localhost"; 
     "127.0.0.1"/8; 
} 

sub vcl_recv { 
    # Purge item from the cache 
     if (req.request == "PURGE") { 
     if (!client.ip ~ purge) { 
      error 405 "Not allowed."; 
     } 

     return (lookup); 
    } 

     # Setting Forwarding header 
    if (req.restarts == 0) { 
     if (req.http.x-forwarded-for) { 
      set req.http.X-Forwarded-For = 
       req.http.X-Forwarded-For + ", " + client.ip; 
     } else { 
      set req.http.X-Forwarded-For = client.ip; 
     } 
    } 

     ## Pipeline ajax requests except of requests for [truncated] 
    if (req.http.X-Requested-With == "XMLHttpRequest" && req.url !~ "^/[truncated]") { 
     return(pipe); 
    } 

    if (req.request != "GET" && 
     req.request != "HEAD" && 
     req.request != "PUT" && 
     req.request != "POST" && 
     req.request != "TRACE" && 
     req.request != "OPTIONS" && 
     req.request != "DELETE") { 
     /* Non-RFC2616 or CONNECT which is weird. */ 
     return (pipe); 
    } 
    if (req.request != "GET" && req.request != "HEAD") { 
     /* We only deal with GET and HEAD by default */ 
     return (pass); 
    } 

    ## Remove GCLID param from googles adds 
    set req.url = regsuball(req.url,"\?gclid=[^&]+$",""); # strips when QS = "?gclid=AAA" 
    set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar" 
    set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz" 

### always cache these items: 

    ## JavaScript 
    if (req.request == "GET" && req.url ~ "\.(js)") { 
     return (lookup); 
    } 

     ## images 
    if (req.request == "GET" && req.url ~ "\.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|img|tga|wmf)$") { 
     return (lookup); 
    } 

     ## various other content pages 
     if (req.request == "GET" && req.url ~ "\.(css|html)$") { 
     return (lookup); 
    }  

    ## multimedia 
    if (req.request == "GET" && req.url ~ "\.(svg|swf|ico|mp3|mp4|m4a|ogg|mov|avi|wmv)$") { 
     return (lookup); 
    } 

     ## xml 
    if (req.request == "GET" && req.url ~ "\.(xml)$") { 
     return (lookup); 
    } 

    ## Do not cache POST requests 
    if (req.request == "POST") { 
     return (pipe); 
    }  

    ## Do not cache the [truncated] 
    if (req.url ~ "^/[truncated]") { 
     return (pipe); 
    } 

    ## Cache the [truncated] 
    if (req.url ~ "^/[truncated]") { 
     return (lookup); 
    } 

    ## Cache the [truncated] 
    if (req.url ~ "^/[truncated]") { 
     return (lookup); 
    } 

    ## Do not cache the [truncated] 
    if (req.url ~ "^/[truncated]") { 
     return (pipe); 
    } 

    ## Exceptions for [truncated] 
    if (req.url ~ "^/[truncated]") { 
     return (pass); 
    } 

    ## Exceptions for [truncated] 
    if (req.url ~ "^/[truncated]") { 
     return (pipe); 
    } 

    return (lookup); 
} 

sub vcl_hash { 

    hash_data(req.url); 
    if (req.http.host) { 
     hash_data(req.http.host); 
    } else { 
     hash_data(server.ip); 
    } 

    ## Make a request to check the logged in status of the current user 
    if (req.request == "GET" && req.url !~ "\.(js|css|html|gif|jpg|jpeg|bmp|png|tiff|tif|ico|img|tga|wmf|svg|swf|ico|mp3|mp4|m4a|ogg|mov|avi|wmv|xml)$" && req.http.cookie ~ "cache-logged-in=1") { 
     hash_data("logged-in"); 
    } 

    return (hash); 
} 

# 
sub vcl_hit { 
    if (req.request == "PURGE") { 
     purge; 
     error 200 "Purged."; 
    } 

    return (deliver); 
} 

# 
sub vcl_miss { 
    if (req.request == "PURGE") { 
     purge; 
     error 200 "Purged."; 
    } 

    return (fetch); 
} 

# 
sub vcl_fetch { 

## If the request to the backend returns a code other than 200, restart the loop 
## If the number of restarts reaches the value of the parameter max_restarts, 
## the request will be error'ed. max_restarts defaults to 4. This prevents 
## an eternal loop in the event that, e.g., the object does not exist at all. 
## this rule also allows for 301's and 302's redirects... 

    ## Unset cookies sent from the backend if they are not necessary 
    if (req.url ~ "[truncated]")) { 
     if (beresp.http.set-cookie !~ "cache-logged-in") { 
      unset beresp.http.set-cookie; 
     } 
    }  

     if (beresp.status != 200 && beresp.status != 403 && beresp.status != 404 && beresp.status != 301 && beresp.status != 302 && beresp.status != 303) { 
     return (restart); 
    } 

    # if I cant connect to the backend, ill set the grace period to be 7200 seconds to hold onto content 
    set beresp.ttl = 7200s; 
    set beresp.grace = 7200s; 

    # If the header X-nocache is present, do not cache the item 
    if (beresp.http.x-nocache) { 
     return (hit_for_pass); 
    } 

    if (beresp.status == 404) { 
     set beresp.ttl = 0s; 
    } 

    if (beresp.status >= 500) { 
     set beresp.ttl = 0s; 
    } 

    if (req.request == "GET" && req.url ~ "\.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|img|tga|wmf)$") { 
     set beresp.ttl = 86400s;  
    } 
    else if (req.request == "GET" && req.url ~ "\.(css|html)$") { 
     ## various other content pages 
     set beresp.ttl = 86400s; 
    } 
    else if (req.request == "GET" && req.url ~ "\.(js)$") { 
     set beresp.ttl = 86400s; 
    } 
    else if (req.request == "GET" && req.url ~ "\.(xml)$") { 
     set beresp.ttl = 86400s; 
    } 
    else if (req.request == "GET" && req.url ~ "\.(svg|swf|ico|mp3|mp4|m4a|ogg|mov|avi|wmv)$") { 
     ## multimedia 
     set beresp.ttl = 86400s; 
    } 
    else { 
     set beresp.http.Expires = "-1"; 
     set beresp.http.Cache-Control = "private, no-cache, no-store, must-revalidate"; 
    } 


    return(deliver); 
} 

답변

0

아파치로 전달 요청이 이미 니스에있는 것과 동일하지는 간단한 설명을 이잖아. 이들이 어떻게 다른지에 관해서는 전체 요청을 볼 필요가 있지만 다음을 포함 할 수있는 여러 가지 옵션이 있습니다. - 쿠키 (아파치 요청이 쿠키를 설정한다는 것을 알기 때문에 내가 시작할 곳을 알 수 있습니다). - URL의 대소 문자 차이 (대소 문자를 구분 함).

+0

하지만 쿠키를 저장하고 보내지 않는 HTTP 요청 생성기에서 정확히 동일한 요청을 보내고 있습니다. 나는 단지 "send"버튼을 누르기 만하고 때로는 바니쉬 (때때로 아파치에서 그리고 다시 바니시에서 응답을 받는다. – filo891

0

unset req.http.cookie in vcl_recv.

+0

그러나 서버에 보내는 요청에는 쿠키 헤더가 전혀 없습니다. – filo891

+0

브라우저에서 확인하십시오. Google Analytics와 도구는 yiur 요청에 쿠키를 추가합니다. 또한 모든 PIPE를 비활성화하고 테스트하십시오. –

+0

브라우저를 사용하고 있지 않습니다. 나는 GET 또는 HEAD 명령 또는이 온라인 도구 인 http://www.hurl.it/을 사용하여 터미널에서 요청을 생성합니다. 동일한 요청이 여러 번 발생하고 요청 중 일부가 Varnish에 의해 처리되고 다른 요청은 Apache로 전달 된 다음 다른 일부는 Varnish에 의해 다시 처리됩니다 (캐시 연령은 이전 응답보다 큼). 요청은 질문에있는 것과 정확히 같습니다. 쿠키가 전혀 없습니다. – filo891

관련 문제