【问题标题】:varnish or squid reverse proxy behind corp proxycorp代理后面的varnish或squid反向代理
【发布时间】:2019-01-14 15:38:59
【问题描述】:

如何配置 varnish(或者如果有人可以提示我使用 squid 我很好)来缓存来自后端的请求,但通过 http_proxy 连接到后端

所以我尝试:

backend default {
    .host = "10.1.1.1";
    .port = "8080";
}

backend corp_proxy {
  .host = "proxy";
  .port = "8080";
}
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.
    set req.backend_hint = corp_proxy;
    set req.url ="http://" + req.http.host + req.url;
}

【问题讨论】:

  • 这是我认为的正确方法,你能告诉我有什么问题吗?

标签: reverse-proxy varnish squid


【解决方案1】:

Varnish(或其他 Web 缓存代理)根据与缓存相关的标头(如 Cache-Control)缓存请求。
不幸的是,许多 Web 应用程序没有正确设置这些标头。所以我们应该使用更激进的方法来缓存一些众所周知的项目,例如图片、.js.css 文件。

此外,set req.url ="http://" + req.http.host + req.url; 这行不是必需的,因为 Varnish 按原样将请求发送到您指定的后端。

这是我推荐的配置:

backend corp_proxy {
  .host = "proxy";
  .port = "8080";
}

sub vcl_recv {
  
  // Determine backend
  if ( req.http.host ~ ".example.com" ) {
    set req.backend_hint = corp_proxy;
    
    // Determine cacheable items
    if( req.url ~ "\.(css|js|jpg|jpeg|png|gif|ico) {
      unset req.http.Cookie;
      unset req.http.Cache-Control;
    }
  }
  
}

sub vcl_backend_response {
  
  if( bereq.http.host ~ ".example.com" ) {
    if (bereq.url ~ "\.(css|jsjpg|jpeg|png|gif|ico)") {
      set beresp.ttl = 20m; // I opt for 20 minutes of caching by your mileage may vary
  }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2010-11-09
    • 2016-12-08
    相关资源
    最近更新 更多