gpt4 book ai didi

reverse-proxy - 公司代理后面的 Varnish 或鱿鱼反向代理

转载 作者:行者123 更新时间:2023-12-03 17:44:49 25 4
gpt4 key购买 nike

如何配置 Varnish (或者如果有人可以提示我使用鱿鱼我很好)来缓存来自后端的请求,但通过 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;
}

最佳答案

Varnish(或其他 Web 缓存代理)根据与缓存相关的 header (如 Cache-Control )缓存请求。
不幸的是,许多 Web 应用程序没有正确设置这些 header 。所以我们应该使用更积极的方法来缓存一些众所周知的项目,例如图片,.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
}

}

关于reverse-proxy - 公司代理后面的 Varnish 或鱿鱼反向代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51728614/

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