gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 17:46:07 27 4
gpt4 key购买 nike

我正在尝试使用 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/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com