2012-02-28 177 views

回答

3

一個可能的原因可能是,你必須在Chrome瀏覽器會話cookie,導致光油將請求傳遞到後端。

+0

是的。我檢查請求中的cookie。他們是不同的。它是由第一次訪問造成的。該響應爲Chrome客戶端設置了一個新的Cookie。 – Hao 2012-03-07 13:58:18

+0

除非您將cookie添加到散列,否則Cookie通常會中斷緩存。 [https://www.varnish-cache.org/trac/wiki/VCLExampleCacheCookies](https://www.varnish-cache.org/trac/wiki/VCLExampleCacheCookies) – 2012-03-26 12:18:01

1

最可能的原因是Accept-Encoding頭的標準化,Firefox和Chrome傳送不同的一個。添加到您的子vcl_recv():

if (req.http.Accept-Encoding) { 
    if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") { 
     # No point in compressing these 
     remove req.http.Accept-Encoding; 
    } elsif (req.http.Accept-Encoding ~ "gzip") { 
     set req.http.Accept-Encoding = "gzip"; 
    } elsif (req.http.Accept-Encoding ~ "deflate") { 
     set req.http.Accept-Encoding = "deflate"; 
    } else { 
     # unkown algorithm 
     remove req.http.Accept-Encoding; 
    } 
} 

這也記錄在Varnish manual on the "Vary" header。其他

+0

我有,但仍Chrome無法緩存 – Hao 2012-03-05 07:25:37

+0

請問你vcl_hash樣子?你是否在varnishlog中看到'Vary:User-Agent'這樣的標題?如果是這樣,那麼指示清漆爲每個用戶代理保留不同的緩存(並且這非常獨特,因爲它也覆蓋了OS字符串等) – Mojah 2012-03-27 10:03:09

0
if (req.http.Accept-Encoding) { 
     if (req.http.Accept-Encoding ~ "gzip") { 
      set req.http.Accept-Encoding = "gzip"; 
     } elsif (req.http.Accept-Encoding ~ "deflate") { 
      set req.http.Accept-Encoding = "deflate"; 
     } else { 
      # unknown language. Remove the accept-language header and 
      # use the backend default. 
      unset req.http.Accept-Encoding; 
     } 
    } 
    //add below condition along with above code in vcl_recv subroutine. 
    if(req.http.User-Agent) { 
     unset req.http.User-Agent; 
    } 
+0

其他明智的,你可以在vcl_deliver子代碼中寫下面的代碼例程以取消設置響應頭中的Vary。 未設置resp.http.Vary; – 2017-05-26 14:20:32

相關問題