caching - Varnish 仅缓存特定的URL路径

标签 caching proxy varnish varnish-vcl

我正在尝试使用 Varnish 来缓存2个网站:

  • http://services.gradle.org
  • http://nodejs.org/dist/

  • 我配置了2个DNS条目:nodejs-proxy和gradle-proxy

    在我的浏览器中,如果我访问http://gradle-proxy,我将被重定向到services.gradle.org的 Varnish 缓存网站。因此,这部分工作。

    但是,我该如何配置它,以便我的 Varnish 机仅在进入http://nodejs.org/dist/时才缓存并显示http://nodejs-proxy

    我的default.vcl配置是:
    backend gradle {
        .host = "207.223.250.8";
        .port = "80";
        .connect_timeout = 6000s;
        .first_byte_timeout = 6000s;
        .between_bytes_timeout = 6000s;
    }
    
    sub vcl_recv {
        # Happens before we check if we have this in cache already.
        #
        # Typically you clean up the request here, removing cookies you don't need,
        # rewriting the request, etc.
    
       if (req.http.host == "gradle-proxy.corp.appdynamics.com") {
          set req.backend_hint = gradle;
       }
    
        if (! req.url ~ "^/dist/") {
            return(pass);
        }
        return(lookup);
    
    }
    

    谢谢

    最佳答案

    嗯,我得到了rm的帮助:

    if (! req.url ~ "^/dist/") {
        return(pass);
    }
    return(lookup);
    

    并添加:
    sub vcl_recv {
        if (req.http.host == "nodejs-proxy") {
                set req.http.host = "nodejs.org";
                set req.url = regsub(req.url, "^", "/dist");
        }
    }
    
    backend nodejs {
        .host = "165.225.133.150";
        .port = "80";
        .connect_timeout = 6000s;
        .first_byte_timeout = 6000s;
        .between_bytes_timeout = 6000s;
    }
    

    关于caching - Varnish 仅缓存特定的URL路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29992215/

    相关文章:

    caching - 如何在 CakePHP 中的模型函数内使用助手

    redirect - 在nginx中修改代理结果的HTTP状态码

    php - Magento 中 Varnish 处于事件状态的 URL 检测

    varnish - 如何在Varnish 4中覆盖vcl_hash方法

    reactjs - create-react-app部署中index.html更改时触发硬缓存刷新

    php - 304 : Not modified and front end caching

    java - 什么是 com.sun.proxy.$Proxy

    caching - Varnish CentOS - 错误 503 后端获取失败

    c# - 如果 ON HEAP 和 OFF HEAP 内存已满,则将条目逐出磁盘 APACHE IGNITE

    c# - 使用C#修改然后显示页面