Varnish Version 3有一些用于不同操作的对象.
例如,当必须从后端检索数据时使用pass.并且当它在缓存中发现请求内容时使用命中.
但我无法理解命中传球的用法.当清漆使用它?我没有在网上找到任何有用的材料让我清楚.
我怎么能print a log在VCL?
我可以在屏幕上打印日志信息吗?
我可以这样做吗?
sub vcl_recv {
....
log.info(req.http.host); // can i write a log here?
....
}
Run Code Online (Sandbox Code Playgroud) 我的配置基于Varnish 3.0,我一直在更新它们.但是我陷入了困境.
vcl_fetch被取代了vcl_backend_response.在vcl_fetch你的内部曾经能够使用req.url但不再在内部vcl_backend_response.
所以我留下三个if不起作用的陈述:
sub vcl_backend_response {
set beresp.do_esi = true;
if (!(req.url ~ "wp-(login|admin)")) {
unset beresp.http.set-cookie;
}
if ( req.http.host ~ "[0-9]\.example\.com" || req.http.host ~ "[0-9]\.example\.com") {
set beresp.ttl = 60s;
}
if ( req.url ~ "\.(html|htm|css|js|txt|xml|svg)(\?[a-z0-9=]+)?$" ) {
set beresp.do_gzip = true;
}
}
Run Code Online (Sandbox Code Playgroud)
如何在Varnish 4.0版中转换这些配置?
顺便说一下,我是Varnish VCL的新手.
我的网站有这个错误
错误503后端提取失败
后端提取失败
大师冥想:
XID:526707
优化缓存服务器
任何人都知道可能是什么原因或如何找出会发生什么?
我正在按照Varnish 3.0.2文档安装Varnish
/etc/varnish/default.vcl
backend default {
.host = "127.0.0.1";
.port = "80";
.connect_timeout = 600s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
}
Run Code Online (Sandbox Code Playgroud)
午餐指挥
sudo varnishd -f /etc/varnish/default.vcl -s malloc,200M -T 127.0.0.1:2000 -a 0.0.0.0:8080
Run Code Online (Sandbox Code Playgroud)
文档:https://www.varnish-cache.org/docs/3.0/tutorial/backend_servers.html
我只是想听:8080,但我得到这个错误:

Varnishlog
[ps] $ varnishlog
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1329118941 1.0
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1329118944 1.0
0 CLI - Rd ping
0 CLI - Wr 200 …Run Code Online (Sandbox Code Playgroud) 我的目标是将某些查询字符串属性及其值"白名单",以便清除不会改变网址之间的缓存.
例:
Url 1: http://foo.com/someproduct.html?utm_code=google&type=hello
Url 2: http://foo.com/someproduct.html?utm_code=yahoo&type=hello
Url 3: http://foo.com/someproduct.html?utm_code=yahoo&type=goodbye
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,我想将"utm_code"列入白名单,但不要"输入".因此,在第一个网址被点击后,我希望varnish将缓存的内容提供给第二个网址.
但是,在第三个url的情况下,属性"type"值不同,因此应该是清漆缓存未命中.
我已经尝试了下面的两种方法(在我现在找不到的drupal帮助文章中找到)似乎不起作用.可能是因为我有正则表达式错误.
# 1. strip out certain querystring values so varnish does not vary cache.
set req.url = regsuball(req.url, "([\?|&])utm_(campaign|content|medium|source|term)=[^&\s]*&?", "\1");
# get rid of trailing & or ?
set req.url = regsuball(req.url, "[\?|&]+$", "");
# 2. strip out certain querystring values so varnish does not vary cache.
set req.url = regsuball(req.url, "([\?|&])utm_campaign=[^&\s]*&?", "\1");
set req.url = regsuball(req.url, "([\?|&])foo_bar=[^&\s]*&?", "\1");
set req.url = regsuball(req.url, "([\?|&])bar_baz=[^&\s]*&?", "\1");
# get …Run Code Online (Sandbox Code Playgroud) 我在Nginx上运行的Wordpress网站上使用Varnish Cache.它的配置方式与本博客中提到的方式相同.它工作正常,但我不确定它是否实际上是从缓存中提供内容.
如何确定?有人可以指导我.我是Varnish缓存的新手.
我的请求流程如下;
HAProxy --> Varnish (4.0.1) --> Apache web backends
Run Code Online (Sandbox Code Playgroud)
当新请求进入HAProxy时,客户端的IP地址将被添加到X-Forwarded-For标头中(这很好!).但是,看起来Varnish HAProxy也在添加IP.当请求到达我的vcl_recv例程时,X-Forwarded-For标题是:
X-Forwarded-For: end-user-ip, haproxy-ip
Run Code Online (Sandbox Code Playgroud)
你可以在varnishlog输出中看到:
* << Request >> 8
- Begin req 7 rxreq
- Timestamp Start: 1409262358.542659 0.000000 0.000000
- Timestamp Req: 1409262358.542659 0.000000 0.000000
- ReqStart 192.168.1.103 48193
- ReqMethod PURGE
- ReqURL /some/path
- ReqProtocol HTTP/1.1
- ReqHeader Authorization: Basic xxx
- ReqHeader User-Agent: curl/7.30.0
- ReqHeader Host: example.com
- ReqHeader Accept: */*
- ReqHeader X-Forwarded-For: 1.2.3.4 …Run Code Online (Sandbox Code Playgroud) 当使用If-Modified-Since: Wed, 15 Feb 2012 07:25:00 CETset 将GET请求直接发送到后端时,Apache正确地返回304而没有内容.
当我通过Varnish 3.0.2发送相同的请求时,它会响应200并重新发送所有内容,即使客户端已经拥有它.显然,这不是一个很好的带宽使用.我的理解是Varnish支持智能处理这个头,应该发送一个304,所以我想我的.vcl文件做错了.
Varnishlog给出了这个:
16 SessionOpen c 84.97.17.233 64416 :80
16 ReqStart c 84.97.17.233 64416 1597323690
16 RxRequest c GET
16 RxURL c /fr/CS/CS_AU-Maboreke-6-6-2004.pdf
16 RxProtocol c HTTP/1.0
16 RxHeader c Host: www.quotaproject.org
16 RxHeader c User-Agent: Sprawk/1.3 (http://www.sprawk.com/)
16 RxHeader c Accept: */*
16 RxHeader c Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
16 RxHeader c Connection: close
16 RxHeader c If-Modified-Since: Wed, 15 Feb 2012 07:25:00 CET
16 VCL_call c recv lookup
16 VCL_call …Run Code Online (Sandbox Code Playgroud) 什么是管道模式和传递模式在varnish-cache ...我一直试图参考这个链接来理解清漆.我有点理解通过,但我想要一个更好的解释.. http://spin.atomicobject.com/2013/01/16/speed-up-website-varnish/