【问题标题】:Varnish HTTP 503 - backend sick - apache static files not cachedVarnish HTTP 503 - 后端生病 - apache 静态文件未缓存
【发布时间】:2017-12-31 11:18:32
【问题描述】:

我们的清漆配置如下:

  • 我们使用 apache 主机和端口进行探测验证,但使用后端(应用程序服务器/mod jk)的上下文。
  • 我们没有使用集群和负载平衡配置。
后端默认{ .host = "127.0.0.1"; .port = "80"; .max_connections = 300; .probe = { .url = "/webapp-context/healthcheck"; .interval = 60s; .timeout = 20s; . 窗口 = 5; . 阈值 = 3; } .first_byte_timeout = 5s; .connect_timeout = 5s; .between_bytes_timeout = 1s; }
  • 我们仅针对特定上下文提供清漆缓存
  • 我们没有静态文件的清漆缓存 (www.domain.com/staticfiles/*),因为所有静态文件都在 DocumentRoot (Apache) 上。
子 vcl_recv { // 不缓存静态文件 if ( req.url ~ "^(/staticfiles)" ) { 返回(通过); } // 创建缓存 if ( req.url ~ "^(/content/)" ) { 取消设置 req.http.Cookie; 返回(哈希); } ... ... }

所以,我的问题是:我们已将 varnish 配置为“通过”静态文件上下文。现在,当我们的后端在探测验证后出现问题时,所有静态文件上下文都出现 HTTP 503 错误,但 html 页面在 Varnish 缓存上仍然正常,但没有静态文件。

是否有任何方法可以配置 Varnish 以继续提供来自 Apache 的所有静态文件,即使应用程序服务器已关闭?

【问题讨论】:

    标签: apache caching varnish


    【解决方案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);
        }
        # ,,,
    }
    

    【讨论】:

    • 非常感谢。这个解决方案解决了我的问题:)
    猜你喜欢
    • 2018-12-20
    • 1970-01-01
    • 1970-01-01
    • 2016-11-02
    • 2016-06-19
    • 2016-12-11
    • 1970-01-01
    • 2013-04-12
    • 1970-01-01
    相关资源
    最近更新 更多