我正在寻找一种方法来清除Varnish中所有域和所有URL的缓存.
目前,我需要为每个URL发出单独的命令,例如:
curl -X PURGE http://example.com/url1
curl -X PURGE http://example.com/url1
curl -X PURGE http://subdomain.example.com/
curl -X PURGE http://subdomain.example.com/url1
// etc.
Run Code Online (Sandbox Code Playgroud)
虽然我正在寻找一种方法来做类似的事情
curl -X PURGE http://example.com/*
Run Code Online (Sandbox Code Playgroud)
这将清除example.com下的所有URL,以及example.com的子域中的所有URL,基本上所有由Varnish管理的URL.
知道怎么做到这一点?
这是我目前的VCL文件:
vcl 4.0;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
# Command to clear the cache
# curl -X PURGE http://example.com
if (req.method == "PURGE") {
return (purge);
}
}
Run Code Online (Sandbox Code Playgroud) 我们正在缓存有问题的 IIS 服务器,该服务器有时只发送空响应(0 字节)而不是正确的响应。缓存这些响应将是一场灾难,而且我们无法解决问题,因为它不是我们的服务器。相反,我想指示 Varnish 如果后端的响应为空(0 字节),则不要缓存它们。
阅读VCL参考(https://www.varnish-cache.org/docs/4.0/reference/vcl.html)我看不到任何明显的方法来解决这个问题。
能做到吗?
在提出这个问题之前,我在谷歌和世界各地搜索了几个小时试图增加Varnish 4和Nginx之间的连接超时,但没有找到解决方案.
所以这是我的清漆配置:
backend web1 {
.host = "192.168.1.21";
.port = "80";
.probe = {
.request =
"HEAD / HTTP/1.1"
"Host: localhost"
"Connection: close";
.timeout = 1s;
.interval = 5s;
.window = 5;
.threshold = 3;
}
.connect_timeout = 300s;
.between_bytes_timeout = 300s;
}
Run Code Online (Sandbox Code Playgroud)
这是Nginx配置:
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 0; # wait for 5 minutes before timeout the request
# proxy_connect_timeout 60s;
# proxy_send_timeout 300s;
# proxy_read_timeout 300s;
fastcgi_read_timeout 300s; …Run Code Online (Sandbox Code Playgroud) 我有2台服务器,一台安装了magento 2(ip-129.89.188.244 80端口),另一台安装了varnish(ip-129.89.188.245 80端口)
我的清漆配置:
文件/ etc/default/varnish: -
DAEMON_OPTS="-a :80 \
-T 127.0.0.1:6082 \
-b 129.89.188.244:80 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
Run Code Online (Sandbox Code Playgroud)
netstat -tulpn: -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1288/sshd
tcp 0 0 127.0.0.1:6082 0.0.0.0:* LISTEN 11115/varnishd
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11115/varnishd
tcp6 0 0 :::22 :::* LISTEN 1288/sshd
tcp6 0 0 :::80 :::* LISTEN 11115/varnishd
Run Code Online (Sandbox Code Playgroud)
/etc/varnish/default.vcl: -
# VCL version 5.0 is not supported so it should be 4.0 even though actually …Run Code Online (Sandbox Code Playgroud) 我真的很惊讶我在任何地方找到这个答案都有这么多麻烦,但我做不到.
使用vcl_recvVarnish 4.0+中的内置VCL 等,默认情况下Varnish缓存404响应吗?
我正在寻找一种方法来遍历整个缓存并获取当前在存储中的对象 URL 列表。
有没有我遗漏的清漆命令。或者有没有人有一个很好的起点来迭代 vmod 中的对象?
问候
在 debian buster 服务器上,我有一个 apache2 Web 服务器,前面有 varnish 作为缓存,实际上 varnish 监听端口 80 并从监听端口 8080 的 apache 获取数据。
\n也许自从从stretch升级后,文件下载不再完成。
\n使用curl下载:
\n$ wget -v -t 1 https://myserver.org/myfile.zip\n--2020-07-10 19:52:34-- https://myserver.org/myfile.zip\nResolving myserver.org (myserver.org)... w.x.y.z\nConnecting to myserver.org (myserver.org)|w.x.y.z|:443... connected.\nHTTP request sent, awaiting response... 200 OK\nLength: 333774113 (318M) [application/zip]\nSaving to: 'myfile.zip.13'\n\nmyfile.zip.13 1%[=> ] 4.43M 8.29MB/s in 0.5s \n\n2020-07-10 19:52:35 (8.29 MB/s) - Connection closed at byte 4649063. Giving up.\nRun Code Online (Sandbox Code Playgroud)\n每个请求的传输量都不同。
\n这是此请求的清漆日志:
\n* << Request >> 2104598 \n- Begin req 2104597 …Run Code Online (Sandbox Code Playgroud) 我不时在日志中看到以下 503 错误:
* << BeReq >> 213585014
- Begin bereq 213585013 fetch
- Timestamp Start: 1452675822.032332 0.000000 0.000000
- BereqMethod GET
- BereqURL /client/hedge-funds-asset-managers/
- BereqProtocol HTTP/1.1
- BereqHeader X-Real-IP: 123.125.71.28
- BereqHeader Host: XXXXXXXXXXXXXXXXXXX
- BereqHeader X-Forwarded-Proto: http
- BereqHeader User-Agent: Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)
- BereqHeader Accept-Encoding: gzip
- BereqHeader Accept-Language: zh-cn,zh-tw
- BereqHeader Accept: */*
- BereqHeader X-Forwarded-For: 172.18.210.22
- BereqHeader X-Varnish: 213585014
- VCL_call BACKEND_FETCH
- VCL_return fetch
- BackendOpen 232 reload_2016-01-12T07:28:50.cp_12 162.251.80.23 80 172.18.210.71 …Run Code Online (Sandbox Code Playgroud) 我正在从这个方便的模板中复制一些 VCL 规则并在最新的稳定版 Varnish4 上运行。但是 VCL 的这一部分:
vcl 4.0;
sub vcl_init {
# ...
# Normalize query arguments
set req.url = std.querysort(req.url);
}
^
Run Code Online (Sandbox Code Playgroud)
返回此错误:
-- Logs begin at Tue 2016-03-15 10:44:31 UTC, end at Tue 2016-03-15 13:02:10 UTC. --
Mar 15 13:02:10 ip-172-31-10-46 reload-vcl[18044]: Message from VCC-compiler:
Mar 15 13:02:10 ip-172-31-10-46 reload-vcl[18044]: Symbol not found: 'std.querysort' (expected type STRING_LIST):
Mar 15 13:02:10 ip-172-31-10-46 reload-vcl[18044]: ('/etc/varnish/test.vcl' Line 55 Pos 23)
Mar 15 13:02:10 ip-172-31-10-46 reload-vcl[18044]: set req.url = …Run Code Online (Sandbox Code Playgroud) 我正在管理一个网站,该网站目前正在运行一个非常标准的 varnish/apache 设置。客户端需要添加一个新域,该域从路径/查询字符串透明地提供服务,以便创建其站点的轻量级版本。例如:
用户访问 mobile.example.com,它指向与 example.com 相同的服务器
Varnish 将 mobile.example.com 请求重写为 example.com/mobile?theme=mobile
用户收到 apache 从 example.com/mobile?theme=mobile 提供的页面,但停留在 mobile.example.com
我们需要点击一个路径并在此处添加查询字符串,以及维护用户输入的任何路径,即:mobile.example.com/test 应在 example.com/mobile/test?theme=mobile 提供内容
使用 Varnish 4 执行此操作的任何提示?是否可以?
在vcl_recv中,我尝试将403发送给网址中包含以下字符的请求:“,',<,>,(和)
if(req.url ~ "[\'\<\>()].*\.html" ) {
return (synth(403, "Forbidden"));
}
Run Code Online (Sandbox Code Playgroud)
一切正常,除了双引号“我尝试了正则表达式:
"[\"\'\<\>()].*\.html"
"[\\"\'\<\>()].*\.html"
"[%22\'\<\>()].*\.html"
"[x22\'\<\>()].*\.html"
Run Code Online (Sandbox Code Playgroud)
它们都不能使用“ varnishd -C -f default.vcl”进行编译。我目前使用varnish-4.1.1。有人知道如何正确地转义“”吗?
varnish-4 ×11
varnish ×9
varnish-vcl ×7
caching ×2
.htaccess ×1
apache ×1
clear-cache ×1
magento-2.0 ×1
nginx ×1
vcl ×1