2017-07-25 90 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