2017-07-25 87 views
1

我們有清漆配置如下:光油HTTP 503 - 後端病 - 阿帕奇靜態文件不會被緩存

  • 我們與Apache主機和端口探測驗證,但使用上下文到後端(應用服務器/ MOD JK)。
  • 我們沒有使用集羣和負載均衡配置。
 

    backend default { 
     .host = "127.0.0.1"; 
     .port = "80"; 
     .max_connections = 300; 

     .probe = { 
      .url = "/webapp-context/healthcheck"; 
      .interval = 60s; 
      .timeout = 20s; 
      .window = 5; 
      .threshold = 3; 
     } 

     .first_byte_timeout  = 5s; 
     .connect_timeout  = 5s; 
     .between_bytes_timeout = 1s; 
    } 

  • 我們只對特定的上下文
  • 我們沒有對staticfiles(www.domain.com/staticfiles/*)清漆漆緩存緩存,因爲所有的靜態文件上的DocumentRoot(阿帕奇)。
 
    sub vcl_recv { 

     // do not cache static files 
     if (req.url ~ "^(/staticfiles)") { 
      return(pass); 
     } 



     // create cache 
     if (req.url ~ "^(/content/)") { 
      unset req.http.Cookie; 
      return(hash); 
     } 

     ... 
     ... 
    } 

所以,我的問題是:我們已經配置了清漆的靜態文件方面做的「通行證」。現在,當我們的後端在探測驗證後生病時,所有的靜態文件上下文都會出現HTTP 503錯誤,但是頁面在Varnish緩存中仍然沒有問題,但是沒有靜態文件。

是否有任何方法配置Varnish以繼續提供來自Apache的所有靜態文件,即使應用程序服務器已關閉?

回答

1

您可以設置附加後端定義將不會指定健康檢查。所以你的VCL將包括這樣的東西:

backend static { 
    .host = "127.0.0.1"; 
    .port = "80"; 
    .max_connections = 300; 
} 

# .. your default backend with probe here 

sub vcl_recv { 
    # ... 
    // do not cache static files 
    if (req.url ~ "^(/staticfiles)") { 
     set req.backend_hint = static; 
     return(pass); 
    } 
    # ,,, 
} 
+0

非常感謝。此解決方案已解決我的問題:) – user3788903