2012-02-18 46 views
1

如果我運行此命令光油:Cacheble但不緩存

varnishtop -i txurl 

該請求是「cacheble」,而不是「緩存」。我看到「年齡= 0」(年齡保持清漆),如何編輯它?

這是我的PHP頁面請求

GET -Used http://example.com

User-Agent: lwp-request/5.810 

200 OK 
Cache-Control: max-age=60, public, must-revalidate 
Connection: close 
Date: Sat, 18 Feb 2012 12:14:33 GMT 
Via: 1.1 varnish 
Age: 0 
Server: Apache 
Vary: Accept-Encoding 
Content-Type: text/html 
Expires: Sat, 18 Feb 2012 12:24:33 GMT 
Client-Date: Sat, 18 Feb 2012 12:14:34 GMT 
Client-Peer: 173.236.219.104:80 
Client-Response-Num: 1 
Client-Transfer-Encoding: chunked 
X-Cache: MISS 
X-Cacheable: YES 
X-Varnish: 840966561 

的.htaccess代碼

# BEGIN Expire headers 
<ifModule mod_expires.c> 
    ExpiresActive On 
    ExpiresDefault "access plus 5 seconds" 
    ExpiresByType image/x-icon "access plus 2592000 seconds" 
    ExpiresByType image/jpeg "access plus 2592000 seconds" 
    ExpiresByType image/png "access plus 2592000 seconds" 
    ExpiresByType image/gif "access plus 2592000 seconds" 
    ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds" 
    ExpiresByType text/css "access plus 604800 seconds" 
    ExpiresByType text/javascript "access plus 216000 seconds" 
    ExpiresByType application/javascript "access plus 216000 seconds" 
    ExpiresByType application/x-javascript "access plus 216000 seconds" 
    ExpiresByType text/html "access plus 600 seconds" 
    ExpiresByType application/xhtml+xml "access plus 600 seconds" 
</ifModule> 
# END Expire headers 

# BEGIN Cache-Control Headers 
<ifModule mod_headers.c> 
    <filesMatch "\.(ico|jpe?g|png|gif|swf)$"> 
    Header set Cache-Control "public" 
    </filesMatch> 
    <filesMatch "\.(css)$"> 
    Header set Cache-Control "public" 
    </filesMatch> 
    <filesMatch "\.(js)$"> 
    Header set Cache-Control "private" 
    </filesMatch> 
    <filesMatch "\.(x?html?|php)$"> 
    Header set Cache-Control "public, must-revalidate" 
    </filesMatch> 
</ifModule> 

Default.vlc

backend default { 
    .host = "173.236.219.104"; 
    .port = "81"; 
    .connect_timeout = 600s; 
    .first_byte_timeout = 600s; 
    .between_bytes_timeout = 600s; 
} 

sub vcl_deliver { 
     if (obj.hits > 0) { 
       set resp.http.X-Cache = "HIT"; 
     } else { 
       set resp.http.X-Cache = "MISS"; 
     } 
} 

sub vcl_fetch { 

    # Varnish determined the object was not cacheable 
    if (beresp.ttl <= 0s) { 
     set beresp.http.X-Cacheable = "NO:Not Cacheable"; 

    # You don't wish to cache content for logged in users 
    } elsif (req.http.Cookie ~ "(UserID|_session)") { 
     set beresp.http.X-Cacheable = "NO:Got Session"; 
     return(hit_for_pass); 

    # You are respecting the Cache-Control=private header from the backend 
    } elsif (beresp.http.Cache-Control ~ "private") { 
     set beresp.http.X-Cacheable = "NO:Cache-Control=private"; 
     return(hit_for_pass); 

    # Varnish determined the object was cacheable 
    } else { 
     set beresp.http.X-Cacheable = "YES"; 
    } 

    # .... 

    return(deliver); 
} 
+0

你能否也請添加清漆配置?只有相關的部分。因爲這聽起來很像清漆配置問題。 – Silenteh 2012-02-18 12:37:31

+0

好的,完成了。更新後 – sparkle 2012-02-18 14:18:44

+0

您可以運行varnishlog,然後運行GET -Used http://example.com或curl -I http://example.com/,然後將varnishlog輸出粘貼到此處? – 2012-02-19 06:16:37

回答

5

大多數後端可能會返回一個cookie,因此varnish不會緩存內容。

關於它的更多資訊:Varnish-Cookies

還有你從LWP得到響應一些不一致的地方。 事實上,我看到一個最大年齡標頭設置爲60秒,我沒有看到在任何地方的後端配置。

對原點的LWP請求也可以幫助調試問題。