Varnish way to explore https:https://cdn.v2ex.com/navatar/ffea/bd22/575_normal.png?m=1402173598 https:https://cdn.v2ex.com/navatar/ffea/bd22/575_large.png?m=1402173598 2018-06-09T05:06:37Z Copyright © 2010-2018, V2EX varnish 如何根据 header 动态设置缓存时间 tag:www.v2ex.com,2018-06-09:/t/461701 2018-06-09T04:09:37Z 2018-06-09T05:06:37Z luger1990 member/luger1990 可能标题问的有点模糊。先说说现在配置 varnish 对某一个 url 缓存的配置吧 是这样的:

if(bereq.url ~ "/api/module/url") { set beresp.ttl = 14400m; #如果请求的 url 为 /api/module/url 那么缓存一天时间 } 

但是我感觉这么一个个 url 设置起来太麻烦了,我能不能在我后端代码( java)中通过设置 header 来动态的去配置,比如我通过 response header 设置

setHeader('varnishCache','true') setHeader('varnishCacheTime','14400m') 

那么我 varnish 的代码设置如下:

if(beresp.http.varnishCache == "true"){ #根据 header 中的信息判断是否缓存 set beresp.ttl = beresp.http.varnishCacheTime;#根据 header 中的时间设置缓存时间 } 

但是上面这么配置 reload varnish 配置的时候会报错。不知道能不能实现我想的配置

既然问了就多问几个问题吧,哈哈哈哈 问题二: 如果我设置一个 url 的缓存时间为 10s,那么 10 秒内都不会发请求到后端,直接 varnish 返回了。万一第 11 秒缓存到期了,恰恰此时我后端服务处问题了返回了 503 或者超时,我能不能还继续用缓存中的数据,避免返回 503 或者 timeout。

希望各位大神指教

]]>
Varnish Explained tag:www.v2ex.com,2016-10-24:/t/315059 2016-10-24T08:23:57Z 2016-10-24T08:23:57Z Livid member/Livid
https://ma.ttias.be/varnish-explained/ ]]> varnish 4.1 和 5.0 现在( 2016 年 10 月 19 日)满满的都是坑别用 tag:www.v2ex.com,2016-10-19:/t/313960 2016-10-19T12:02:09Z 2016-10-19T12:54:50Z baskice member/baskice
访问就会出现 empty response 。蛋疼的是这个完全没有任何请求,导致看 log 都没法 debug ,因为没有 log 。配置也没报错。

我从 3.0 开始一路用到 5.0 。 varnish 越做越差了,大家还是找别的反向代理缓存软件吧 ]]>
Varnish Cache 5.0 tag:www.v2ex.com,2016-09-20:/t/307538 2016-09-20T06:56:59Z 2016-09-20T07:49:22Z iCodex member/iCodex https://varnish-cache.org/docs/5.0/whats-new/relnote-5.0.html

新增独立加载 vcl 这项功能,这样不同的域名或类型的应用,就可以单独加载不同的 vcl 配置,避免了混乱不堪的 vcl 结构,看到头炸。
还有鸡肋的 http 2.0 的支持,相信后面的版本会完善好这项 ]]>
启用缓存后,大家如何解决网站即时显示新添加或修改的内容? tag:www.v2ex.com,2015-05-26:/t/193932 2015-05-26T12:57:10Z 2015-05-26T12:54:10Z boro member/boro 大家帮忙看下这段 Varnish 缓存规则是什么原因导致的语法错误 tag:www.v2ex.com,2015-04-13:/t/183478 2015-04-13T11:26:33Z 2015-04-13T11:23:33Z boro member/boro Message from VCC-compiler:

Syntax error at

('input' Line 29 Pos 17)

if (req.url ~ "\ (utm_ (campaign |? medium | source | term) | adParams | client | cx | eid | fbid | feed | ref (id | src) |? v (er | iew)) =" ) {

---------------- # --------------------------------- -------------------------------------------------- -------------------

Running VCC-compiler failed, exit 1

这个错在哪呢?

全部缓存规则如下:

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

sub vcl_recv {
if (req.http.Accept-Encoding) {
#revisit this list
if (req.url ~ "\.(gif|jpg|jpeg|swf|flv|mp3|mp4|pdf|ico|png|gz|tgz|bz2)(\?.*|)$") {
remove req.http.Accept-Encoding;
} elsif (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} elsif (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
remove req.http.Accept-Encoding;
}
}
if (req.url ~ "\.(gif|jpg|jpeg|swf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
unset req.http.cookie;
set req.url = regsub(req.url, "\?.*$", "");
}
if (req.url ~ “\?(utm_(campaign|medium|source|term)|adParams|client|cx|eid|fbid|feed|ref(id|src)?|v(er|iew))=”) {
set req.url = regsub(req.url, “\?.*$”, “”);
}
if (req.http.cookie) {
if (req.http.cookie ~ "(wordpress_|wp-settings-)") {
return(pass);
} else {
unset req.http.cookie;
}
}
}

sub vcl_fetch {
if (req.url ~ "wp-(login|admin)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php") {
return (hit_for_pass);
}
if ( (!(req.url ~ "(wp-(login|admin)|login)")) || (req.request == "GET") ) {
unset beresp.http.set-cookie;
}
if (req.url ~ "\.(gif|jpg|jpeg|swf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
set beresp.ttl = 365d;
}
}

sub vcl_deliver {
# multi-server webfarm? set a variable here so you can check
# the headers to see which frontend served the request
# set resp.http.X-Server = "server-01";
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
} ]]>
Fastly 写的他们为什么用 Varnish 做 CDN 的理由 tag:www.v2ex.com,2015-04-01:/t/181012 2015-04-01T22:00:55Z 2015-04-02T00:22:27Z Livid member/Livid http://www.fastly.com/blog/benefits-of-using-varnish/ ]]> Varnish Massive Storage Engine tag:www.v2ex.com,2014-12-05:/t/151886 2014-12-05T23:40:10Z 2014-12-05T23:40:10Z Livid member/Livid https://www.varnish-software.com/blog/introducing-varnish-massive-storage-engine ]]> Varnish/nginx 反向代理如何解决后端获取 server_addr 是 127.0.0.1 的问题 tag:www.v2ex.com,2014-09-09:/t/132428 2014-09-09T04:33:00Z 2014-09-09T09:16:26Z loveminds member/loveminds Varnish 一般是放在 Nginx 前面还是后面的? tag:www.v2ex.com,2014-07-07:/t/121433 2014-07-07T15:01:20Z 2014-07-07T19:51:01Z 9 member/9 求助:关于 varnish 配置的问题 tag:www.v2ex.com,2014-05-30:/t/115058 2014-05-30T08:07:55Z 2014-05-30T10:10:29Z solar member/solar

我在web服务器的8383端口上部署了一个网站。现在要用varnish为它提供缓存服务。不知道怎么配置。查了很多资料,但是我始终没能在Headers里看到X-Varnish。varnish和web服务在同一台服务器上。

/etc/varnish/default.vcl
<pre>
# This is a basic VCL configuration file for varnish. See the vcl(7)
# man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# server.
#
import std;

probe healthchk {
.url = "/";
.interval = 3s;
.timeout = 10ms;
.window = 3;
.threshold = 2;
.initial = 3;
.expected_respOnse= 200;
}

backend default {
.host = "xx.xx.xx.xx";
.port = "8383";
.probe = healthchk;
}

#acl purge {
# "localhost";
# "127.0.0.1";
# "xx.xx.xx.xx"/24;
#}

#
# Below is a commented-out copy of the default VCL logic. If you
# redefine any of these subroutines, the built-in logic will be
# appended to your code.
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
/* Not cacheable by default */
return (pass);
}
return (lookup);
}

sub vcl_pipe {
# Note that only the first request to the backend will have
# X-Forwarded-For set. If you use X-Forwarded-For and want to
# have it set for all requests, make sure to have:
# set bereq.http.cOnnection= "close";
# here. It is not set by default as it might break some broken web
# applications, like IIS with NTLM authentication.
return (pipe);
}

sub vcl_pass {
return (pass);
}

sub vcl_hash {
hash_data(req.url);
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
return (hash);
}

sub vcl_hit {
return (deliver);
}

sub vcl_miss {
return (fetch);
}

sub vcl_fetch {
if (beresp.ttl <= 0s ||
beresp.http.Set-Cookie ||
beresp.http.Vary == "*") {
/*
* Mark as "Hit-For-Pass" for the next 2 minutes
*/
set beresp.ttl = 120 s;
return (hit_for_pass);
}
return (deliver);
}

sub vcl_deliver {
return (deliver);
}

sub vcl_error {
set obj.http.Content-Type = "text/html; charset=utf-8";
set obj.http.Retry-After = "5";
synthetic {"
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>"} + obj.status + " " + obj.response + {"</title>
</head>
<body>
<h1>Error "} + obj.status + " " + obj.response + {"</h1>
<p>"} + obj.response + {"</p>
<h3>Guru Meditation:</h3>
<p>XID: "} + req.xid + {"</p>
<hr>
<p>Varnish cache server</p>
</body>
</html>
"};
return (deliver);
}

sub vcl_init {
return (ok);
}

sub vcl_fini {
return (ok);
}
</pre>
----------------------------------------------------------------------------
/etc/sysconfig/varnish
<pre>
# Configuration file for varnish
#
# /etc/init.d/varnish expects the variable $DAEMON_OPTS to be set from this
# shell script fragment.
#

# Maximum number of open files (for ulimit -n)
NFILES=131072

# Locked shared memory (for ulimit -l)
# Default log size is 82MB + header
MEMLOCK=82000

# Maximum number of threads (for ulimit -u)
NPROCS="unlimited"

# Maximum size of corefile (for ulimit -c). Default in Fedora is 0
# DAEMON_COREFILE_LIMIT="unlimited"

# Set this to 1 to make init script reload try to switch vcl without restart.
# To make this work, you need to set the following variables
# explicit: VARNISH_VCL_CONF, VARNISH_ADMIN_LISTEN_ADDRESS,
# VARNISH_ADMIN_LISTEN_PORT, VARNISH_SECRET_FILE, or in short,
# use Alternative 3, Advanced configuration, below
RELOAD_VCL=1

# This file contains 4 alternatives, please use only one.

## Alternative 1, Minimal configuration, no VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# content server on localhost:8080. Use a fixed-size cache file.
#
#DAEMON_OPTS="-a :6081 \
# -T localhost:6082 \
# -b localhost:8080 \
# -u varnish -g varnish \
# -s file,/var/lib/varnish/varnish_storage.bin,1G"


## Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# one content server selected by the vcl file, based on the request. Use a
# fixed-size cache file.
#
#DAEMON_OPTS="-a :6081 \
# -T localhost:6082 \
# -f /etc/varnish/default.vcl \
# -u varnish -g varnish \
# -S /etc/varnish/secret \
# -s file,/var/lib/varnish/varnish_storage.bin,1G"


## Alternative 3, Advanced configuration
#
# See varnishd(1) for more information.
#
# # Main configuration file. You probably want to change it :)
VARNISH_VCL_COnF=/etc/varnish/default.vcl
#
# # Default address and port to bind to
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=
VARNISH_LISTEN_PORT=80
#
# # Telnet admin interface listen address and port
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
VARNISH_ADMIN_LISTEN_PORT=6082
#
# # Shared secret file for admin interface
VARNISH_SECRET_FILE=/etc/varnish/secret
#
# # The minimum number of worker threads to start
VARNISH_MIN_THREADS=50
#
# # The Maximum number of worker threads to start
VARNISH_MAX_THREADS=1000
#
# # Idle timeout for worker threads
VARNISH_THREAD_TIMEOUT=120
#
# # Cache file location
VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin
#
# # Cache file size: in bytes, optionally using k / M / G / T suffix,
# # or in percentage of available disk space using the % suffix.
VARNISH_STORAGE_SIZE=1G
#
# # Backend storage specification
VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
#
# # Default TTL used when the backend does not specify one
VARNISH_TTL=120
#
# # DAEMON_OPTS is used by the init script. If you add or remove options, make
# # sure you update this section, too.
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
-f ${VARNISH_VCL_CONF} \
-T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
-t ${VARNISH_TTL} \
-w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \
-u varnish -g varnish \
-S ${VARNISH_SECRET_FILE} \
-s ${VARNISH_STORAGE}"
#


## Alternative 4, Do It Yourself. See varnishd(1) for more information.
#
# DAEMON_OPTS=""
</pre> ]]>
VML tag:www.v2ex.com,2014-05-13:/t/112441 2014-05-13T22:27:05Z 2014-05-13T22:27:05Z Livid member/Livid http://phk.freebsd.dk/VML/index.html ]]> Varnish Cache 4.0.0 tag:www.v2ex.com,2014-05-13:/t/112439 2014-05-13T21:42:18Z 2014-05-13T22:42:18Z Livid member/Livid https://www.varnish-cache.org/content/varnish-cache-400 ]]> varnish可以走ssl吗 tag:www.v2ex.com,2013-12-16:/t/93359 2013-12-16T07:43:54Z 2013-12-16T07:40:54Z kingwkb member/kingwkb
varnish 和nginx上面都走ssl ]]>
怎么处理Varnish 动态输出? tag:www.v2ex.com,2013-12-11:/t/92714 2013-12-11T06:54:36Z 2013-12-11T08:39:54Z h2sky member/h2sky echo rand(1,99);
?>

输出的是43,之后输出的还是43,需要过1分钟左右再更新

怎么办? ]]>
ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86