23. Browser
cache:
in
Apache
ExpiresAc*ve
on
ExpiresDefault
"access
plus
1
month"
ExpiresDefault
"now
plus
4
weeks"
ExpiresDefault
"modifica*on
plus
30
days"
ExpiresByType
text/html
"access
plus
1
month
15
days
2
hours"
49. Varnishlog
varnishlog
-‐w
/tmp/yourfile.log
Write
log
to
file
varnishlog
-‐r
/tmp/yourfile.log
Read
log
from
file
50.
12
SessionOpen
c
172.16.26.1
50396
:8080
12
ReqStart
c
172.16.26.1
50396
668213522
12
RxRequest
c
GET
12
RxURL
c
/test.php
12
RxProtocol
c
HTTP/1.1
12
RxHeader
c
Host:
varnish.dev:8080
12
RxHeader
c
User-‐Agent:
Mozilla/5.0
(Macintosh;
U;
Intel
Mac
OS
X
10.6;
nl;
rv:1.9.2.10)
Gecko/20100914
Firefox/3.6.10
12
RxHeader
c
Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8
12
RxHeader
c
Accept-‐Language:
nl,en-‐us;q=0.7,en;q=0.3
12
RxHeader
c
Accept-‐Encoding:
gzip,deflate
12
RxHeader
c
Accept-‐Charset:
ISO-‐8859-‐1,utf-‐8;q=0.7,*;q=0.7
12
RxHeader
c
Keep-‐Alive:
115
12
RxHeader
c
Connection:
keep-‐alive
12
RxHeader
c
Cookie:
PHPSESSID=2n2pkit81qdgk6k4trf1crft16
12
VCL_call
c
recv
12
VCL_return
c
pass
12
VCL_call
c
hash
12
VCL_return
c
hash
12
VCL_call
c
pass
12
VCL_return
c
pass
14
BackendClose
-‐
default
14
BackendOpen
b
default
127.0.0.1
34267
127.0.0.1
80
12
Backend
c
14
default
default
51.
14
TxRequest
b
GET
14
TxURL
b
/test.php
14
TxProtocol
b
HTTP/1.1
14
TxHeader
b
Host:
varnish.dev:8080
14
TxHeader
b
User-‐Agent:
Mozilla/5.0
(Macintosh;
U;
Intel
Mac
OS
X
10.6;
nl;
rv:1.9.2.10)
Gecko/20100914
Firefox/3.6.10
14
TxHeader
b
Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8
14
TxHeader
b
Accept-‐Language:
nl,en-‐us;q=0.7,en;q=0.3
14
TxHeader
b
Accept-‐Encoding:
gzip,deflate
14
TxHeader
b
Accept-‐Charset:
ISO-‐8859-‐1,utf-‐8;q=0.7,*;q=0.7
14
TxHeader
b
Cookie:
PHPSESSID=2n2pkit81qdgk6k4trf1crft16
14
TxHeader
b
X-‐Forwarded-‐For:
172.16.26.1
14
TxHeader
b
X-‐Varnish:
668213522
14
RxProtocol
b
HTTP/1.1
14
RxStatus
b
200
14
RxResponse
b
OK
14
RxHeader
b
Date:
Tue,
19
Oct
2010
12:54:49
GMT
14
RxHeader
b
Server:
Apache/2.2.16
(Ubuntu)
14
RxHeader
b
X-‐Powered-‐By:
PHP/5.3.3-‐1ubuntu9
14
RxHeader
b
Vary:
Accept-‐Encoding
14
RxHeader
b
Content-‐Encoding:
gzip
14
RxHeader
b
Content-‐Length:
36
14
RxHeader
b
Content-‐Type:
text/html
52.
12
TTL
c
668213522
RFC
120
1287492889
0
0
0
0
12
VCL_call
c
fetch
12
TTL
c
668213522
VCL
10
1287492889
12
VCL_return
c
pass
12
ObjProtocol
c
HTTP/1.1
12
ObjStatus
c
200
12
ObjResponse
c
OK
12
ObjHeader
c
Date:
Tue,
19
Oct
2010
12:54:49
GMT
12
ObjHeader
c
Server:
Apache/2.2.16
(Ubuntu)
12
ObjHeader
c
X-‐Powered-‐By:
PHP/5.3.3-‐1ubuntu9
12
ObjHeader
c
Vary:
Accept-‐Encoding
12
ObjHeader
c
Content-‐Encoding:
gzip
12
ObjHeader
c
Content-‐Type:
text/html
14
Length
b
36
14
BackendReuse
b
default
12
VCL_call
c
deliver
12
VCL_return
c
deliver
12
TxProtocol
c
HTTP/1.1
12
TxStatus
c
200
12
TxResponse
c
OK
12
TxHeader
c
Server:
Apache/2.2.16
(Ubuntu)
12
TxHeader
c
X-‐Powered-‐By:
PHP/5.3.3-‐1ubuntu9
12
TxHeader
c
Vary:
Accept-‐Encoding
12
TxHeader
c
Content-‐Encoding:
gzip
12
TxHeader
c
Content-‐Type:
text/html
12
TxHeader
c
Content-‐Length:
36
12
TxHeader
c
Date:
Tue,
19
Oct
2010
12:54:49
GMT
12
TxHeader
c
X-‐Varnish:
668213522
12
TxHeader
c
Age:
0
12
TxHeader
c
Via:
1.1
varnish
53. Varnishtop
Read
memory
logs
and
presents
them
as
a
con*nuously
updated
list
of
commonly
occuring
log
entries
hZp://www.varnish-‐cache.org/docs/2.1/reference/varnishtop.html
58. Varnishncsa
Read
memory
logs
and
presents
them
in
the
Apache
/
NCSA
“combined”
log
format
hZp://www.varnish-‐cache.org/docs/2.1/reference/varnishncsa.html
59. Varnishncsa
varnishncsa
-‐D
-‐a
-‐w
/var/log/some.log
172.16.26.1
-‐
-‐
[19/Oct/2010:16:08:02
+0200]
"GET
hZp://
varnish.dev:8080/
HTTP/1.1"
200
97
"-‐"
"Mozilla/5.0
(Macintosh;
U;
Intel
Mac
OS
X
10.6;
nl;
rv:1.9.2.10)
Gecko/20100914
Firefox/3.6.10"
172.16.26.1
-‐
-‐
[19/Oct/2010:16:08:10
+0200]
"GET
hZp://
varnish.dev:8080/test.php
HTTP/1.1"
200
36
"-‐"
"Mozilla/5.0
(Macintosh;
U;
Intel
Mac
OS
X
10.6;
nl;
rv:1.9.2.10)
Gecko/20100914
Firefox/3.6.10"
60. Varnishreplay
The
varnishreplay
u*lity
parses
varnish
logs
and
aZempts
to
reproduce
the
traffic
hZp://www.varnish-‐cache.org/docs/2.1/reference/varnishreplay.html
63. Management
via
telnet
root@dev:/#
telnet
localhost
6082
Trying
::1...
Connected
to
localhost.
Escape
character
is
'^]'.
200
154
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
Varnish
HTTP
accelerator
CLI.
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
Type
'help'
for
command
list.
Type
'quit'
to
close
CLI
session.
69. Cache
...
even
with
cookies
sub vcl_recv {
if (req.request == "GET" || req.request ==
"HEAD") {
return (lookup);
}
}
sub vcl_hash {
if (req.http.Cookie) {
set req.hash += req.http.Cookie;
}
}
70. Remove
cookies
sub vcl_recv {
unset req.http.cookie;
}
sub vcl_fetch {
unset beresp.http.set-cookie;
}
71. Remove
Google
Analy*cs
cookies
sub vcl_recv {
if (req.http.Cookie) {
set req.http.Cookie = regsuball
(req.http.Cookie,"(^|; ) *__utm.=[^;]+;?
*","1");
if (req.http.Cookie == "") {
remove req.http.Cookie;
}
}
74. Grace
mode
sub vcl_recv {
if (req.backend.healthy) {
set req.grace = 1s;
} else {
set req.grace = 10s;
}
}
Keep
reading
from
cache,
even
when
expired
80. Loadbalancing
via
directors
director back round-robin {
{.backend = default;}
{.backend = other;}
}
sub vcl_recv {
set req.backend = back;
return(pass);
}
82. Loadbalancing
via
directors
director back random {
{.backend = default; .weight=1;}
{.backend = other; .weight=2;}
}
sub vcl_recv {
set req.backend = back;
return(pass);
}