1
.\" Man page generated from reStructeredText.
3
.TH VCL 7 "2010-06-02" "1.0" ""
5
VCL \- Varnish Configuration Language
7
.nr rst2man-indent-level 0
11
level \\n[rst2man-indent-level]
12
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
19
.\" .rstReportMargin pre:
21
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
22
. nr rst2man-indent-level +1
23
.\" .rstReportMargin post:
27
.\" indent \\n[an-margin]
28
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
29
.nr rst2man-indent-level -1
30
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
31
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
35
The VCL language is a small domain\-specific language designed to be
36
used to define request handling and document caching policies for
39
When a new configuration is loaded, the varnishd management process
40
translates the VCL code to C and compiles it to a shared object which
41
is then dynamically linked into the server process.
44
The VCL syntax is very simple, and deliberately similar to C and Perl.
45
Blocks are delimited by curly braces, statements end with semicolons,
46
and comments may be written as in C, C++ or Perl according to your own
49
In addition to the C\-like assignment (=), comparison (==, !=) and
50
boolean (!, && and ||) operators, VCL supports both regular
51
expression and ACL matching using the ~ and the !~ operators.
53
Basic strings are enclosed in " ... ", and may not contain newlines.
55
Long strings are enclosed in {" ... "}. They may contain any
56
character including ", newline and other control characters except
57
for the NUL (0x00) character.
59
Unlike C and Perl, the backslash () character has no special meaning
60
in strings in VCL, so it can be freely used in regular expressions
63
Strings are concatenated using the \(aq+\(aq operator.
65
Assignments are introduced with the \fIset\fP keyword. There are no
66
user\-defined variables; values can only be assigned to variables
67
attached to backend, request or document objects. Most of these are
68
typed, and the values assigned to them must have a compatible unit
71
You can use the \fIset\fP keyword to arbitrary HTTP headers. You can
72
remove headers with the \fIremove\fP or \fIunset\fP keywords, which are
75
You can use the \fIrollback\fP keyword to revert any changes to req at
78
The \fIsynthetic\fP keyword is used to produce a synthetic response
79
body in vcl_error. It takes a single string as argument.
81
You can force a crash of the client process with the \fIpanic\fP keyword.
82
\fIpanic\fP takes a string as argument.
84
The \fBreturn(action)\fP keyword terminates the subroutine. \fIaction\fP can be,
85
depending on context one of
109
Please see the list of subroutines to see what return actions are
112
VCL has if tests, but no loops.
114
The contents of another VCL file may be inserted at any point in the
115
code by using the \fIinclude\fP keyword followed by the name of the other
116
file as a quoted string.
117
.SS Backend declarations
119
A backend declaration creates and initializes a named backend object::
124
.host = "www.example.com";
130
The backend object can later be used to select a backend at request time::
134
if (req.http.host ~ "(?i)^(www.)?example.com$") {
135
set req.backend = www;
140
To avoid overloading backend servers, .max_connections can be set to
141
limit the maximum number of concurrent backend connections.
143
The timeout parameters can be overridden in the backend declaration.
144
The timeout parameters are .connect_timeout for the time to wait for a
145
backend connection, .first_byte_timeout for the time to wait for the
146
first byte from the backend and .between_bytes_timeout for time to
147
wait between each received byte.
149
These can be set in the declaration like this::
154
.host = "www.example.com";
156
.connect_timeout = 1s;
157
.first_byte_timeout = 5s;
158
.between_bytes_timeout = 2s;
163
To mark a backend as unhealthy after number of items have been added
164
to its saintmode list \fB.saintmode_threshold\fP can be set to the maximum
165
list size. Setting a value of 0 disables saint mode checking entirely
166
for that backend. The value in the backend declaration overrides the
170
A director is a logical group of backend servers clustered together
171
for redundancy. The basic role of the director is to let Varnish
172
choose a backend server amongst several so if one is down another can
175
There are several types of directors. The different director types
176
use different algorithms to choose which backend to use.
178
Configuring a director may look like this::
185
// We can refer to named backends
190
// Or define them inline
199
.SS The family of random directors
201
There are three directors that share the same logic, called the random
202
director, client director and hash director. They each distribute traffic
203
among the backends assigned to it using a random distribution seeded with
204
either the client identity, a random number or the cache hash (typically
205
url). Beyond the initial seed, they act the same.
207
Each backend requires a .weight option which sets the amount of traffic
208
each backend will get compared to the others. Equal weight means equal
209
traffic. A backend with lower weight than an other will get proportionally
212
The director has an optional .retries option which defaults to the number
213
of backends the director has. The director will attempt .retries times to
214
find a healthy backend if the first attempt fails. Each attempt re\-uses the
215
previous seed in an iterative manner. For the random director this detail
216
is of no importance as it will give different results each time. For the
217
hash and client director, this means the same URL or the same client will
218
fail to the same server consistently.
219
.SS The random director
221
This uses a random number to seed the backend selection.
222
.SS The client director
224
The client director picks a backend based on the clients
225
\fIidentity\fP. You can set the VCL variable \fIclient.identity\fP to identify
226
the client by picking up the value of a session cookie or similar.
227
.SS The hash director
229
The hash director will pick a backend based on the URL hash
232
This is useful is you are using Varnish to load balance in front of
233
other Varnish caches or other web accelerators as objects won\(aqt be
234
duplicated across caches.
236
It will use the value of req.hash, just as the normal cache\-lookup methods.
237
.SS The round\-robin director
239
The round\-robin director does not take any options.
241
It will use the first backend for the first request, the second backend for
242
the second request and so on, and start from the top again when it gets to
245
If a backend is unhealthy or Varnish fails to connect, it will be skipped.
246
The round\-robin director will try all the backends once before giving up.
249
The DNS director can use backends in two different ways. Either like the
250
random or round\-robin director or using .list:
254
director directorname dns {
256
.host_header = "www.example.com";
258
.connect_timeout = 0.4s;
263
.suffix = "internal.example.net";
268
This will specify 384 backends, all using port 80 and a connection timeout
269
of 0.4s. Options must come before the list of IPs in the .list statement.
270
The .list\-method does not support IPv6. It is not a white\-list, it is an
271
actual list of backends that will be created internally in Varnish \- the
272
larger subnet the more overhead.
274
The .ttl defines the cache duration of the DNS lookups.
276
The above example will append "internal.example.net" to the incoming Host
277
header supplied by the client, before looking it up. All settings are
280
Health checks are not thoroughly supported.
282
DNS round robin balancing is supported. If a hostname resolves to multiple
283
backends, the director will divide the traffic between all of them in a
285
.SS The fallback director
287
The fallback director will pick the first backend that is healthy. It
288
considers them in the order in which they are listed in its definition.
290
The fallback director does not take any options.
292
An example of a fallback director:
296
director b3 fallback {
298
{ .backend = www2; } // will only be used if www1 is unhealthy.
299
{ .backend = www3; } // will only be used if both www1 and www2
306
Backends can be probed to see whether they should be considered
307
healthy or not. The return status can also be checked by using
310
Probes take the following parameters:
314
Specify a URL to request from the backend.
318
Specify a full HTTP request using multiple strings. .request will
319
have \er\en automatically inserted after every string.
320
If specified, .request will take precedence over .url.
323
How many of the latest polls we examine to determine backend health.
327
How many of the polls in .window must have succeeded for us to consider
332
How many of the probes are considered good when Varnish starts.
333
Defaults to the same amount as the threshold.
335
.B .expected_response
336
The expected backend HTTP response code.
340
Defines how often the probe should check the backend.
341
Default is every 5 seconds.
344
How fast each probe times out.
345
Default is 2 seconds.
348
A backend with a probe can be defined like this, together with the
349
backend or director::
354
.host = "www.example.com";
367
Or it can be defined separately and then referenced::
372
.url = "/status.cgi";
378
.expected_response = 200;
382
.host = "www.example.com";
384
.probe = healthcheck;
389
If you have many backends this can simplify the config a lot.
391
It is also possible to specify the raw HTTP request:
396
# NB: \er\en automatically inserted after each string!
406
An ACL declaration creates and initializes a named access control list
407
which can later be used to match client addresses::
412
"localhost"; // myself
413
"192.0.2.0"/24; // and everyone on the local network
414
! "192.0.2.23"; // except for the dialin router
419
If an ACL entry specifies a host name which Varnish is unable to
420
resolve, it will match any address it is com‐ pared to. Consequently,
421
if it is preceded by a negation mark, it will reject any address it is
422
compared to, which may not be what you intended. If the entry is
423
enclosed in parentheses, however, it will simply be ignored.
425
To match an IP address against an ACL, simply use the match operator::
429
if (client.ip ~ local) {
434
.SS Regular Expressions
436
In Varnish 2.1.0 Varnish switched to using PCRE \- Perl\-compatible
437
regular expressions. For a complete description of PCRE please see the
440
To send flags to the PCRE engine, such as to turn on \fIcase
441
insensitivity\fP add the flag within parens following a question mark,
446
if (req.http.host ~ "(?i)example.com$") {
453
The following built\-in functions are available:
457
Adds a string to the hash input. In default.vcl hash_data() is
458
called on the host and URL of the \fIrequest\fP.
460
.B regsub(str, regex, sub)
461
Returns a copy of str with the first occurrence of the regular
462
expression regex replaced with sub. Within sub, 0 (which can
463
also be spelled &) is replaced with the entire matched string,
464
and n is replaced with the contents of subgroup n in the
467
.B regsuball(str, regex, sub)
468
As regsuball() but this replaces all occurrences.
475
Bans all objects in cache whose URLs match regex.
479
A subroutine is used to group code for legibility or reusability::
484
if (client.ip ~ local) {
491
Subroutines in VCL do not take arguments, nor do they return values.
493
To call a subroutine, use the call keyword followed by the subroutine\(aqs name:
497
There are a number of special subroutines which hook into the Varnish
498
workflow. These subroutines may inspect and manipulate HTTP headers
499
and various other aspects of each request, and to a certain extent
500
decide how the request should be handled. Each subroutine terminates
501
by calling one of a small number of keywords which indicates the
506
Called when VCL is loaded, before any requests pass through it.
507
Typically used to initialize VMODs.
513
Normal return, VCL continues loading.
517
Called at the beginning of a request, after the complete request has
518
been received and parsed. Its purpose is to decide whether or not
519
to serve the request, how to do it, and, if applicable, which backend
522
The vcl_recv subroutine may terminate with calling return() on one of
523
the following keywords:
526
.B error code [reason]
527
Return the specified error code to the client and abandon the request.
530
Switch to pass mode. Control will eventually pass to vcl_pass.
533
Switch to pipe mode. Control will eventually pass to vcl_pipe.
536
Look up the requested object in the cache. Control will
537
eventually pass to vcl_hit or vcl_miss, depending on whether the
538
object is in the cache.
542
Called upon entering pipe mode. In this mode, the request is passed
543
on to the backend, and any further data from either client or
544
backend is passed on unaltered until either end closes the
547
The vcl_pipe subroutine may terminate with calling return() with one of
548
the following keywords:
551
.B error code [reason]
552
Return the specified error code to the client and abandon the request.
555
Proceed with pipe mode.
559
Called upon entering pass mode. In this mode, the request is passed
560
on to the backend, and the backend\(aqs response is passed on to the
561
client, but is not entered into the cache. Subsequent requests sub‐
562
mitted over the same client connection are handled normally.
564
The vcl_recv subroutine may terminate with calling return() with one of
565
the following keywords:
568
.B error code [reason]
569
Return the specified error code to the client and abandon the request.
572
Proceed with pass mode.
575
Restart the transaction. Increases the restart counter. If the number
576
of restarts is higher than \fImax_restarts\fP varnish emits a guru meditation
581
You may call hash_data() on the data you would like to add to the hash.
583
The vcl_hash subroutine may terminate with calling return() with one of
584
the following keywords:
592
Called after a cache lookup if the requested document was found in the cache.
594
The vcl_hit subroutine may terminate with calling return() with one of
595
the following keywords:
599
Deliver the cached object to the client. Control will eventually
602
.B error code [reason]
603
Return the specified error code to the client and abandon the request.
606
Switch to pass mode. Control will eventually pass to vcl_pass.
609
Restart the transaction. Increases the restart counter. If the number
610
of restarts is higher than \fImax_restarts\fP varnish emits a guru meditation
615
Called after a cache lookup if the requested document was not found
616
in the cache. Its purpose is to decide whether or not to attempt to
617
retrieve the document from the backend, and which backend to use.
619
The vcl_miss subroutine may terminate with calling return() with one of
620
the following keywords:
623
.B error code [reason]
624
Return the specified error code to the client and abandon the request.
627
Switch to pass mode. Control will eventually pass to vcl_pass.
630
Retrieve the requested object from the backend. Control will
631
eventually pass to vcl_fetch.
635
Called after a document has been successfully retrieved from the backend.
637
The vcl_fetch subroutine may terminate with calling return() with
638
one of the following keywords:
642
Possibly insert the object into the cache, then deliver it to the
643
client. Control will eventually pass to vcl_deliver.
645
.B error code [reason]
646
Return the specified error code to the client and abandon the request.
649
Pass in fetch. This will create a hit_for_pass object. Note that
650
the TTL for the hit_for_pass object will be set to what the
651
current value of beresp.ttl. Control will be handled to
652
vcl_deliver on the current request, but subsequent requests will
653
go directly to vcl_pass based on the hit_for_pass object.
656
Restart the transaction. Increases the restart counter. If the number
657
of restarts is higher than \fImax_restarts\fP varnish emits a guru meditation
662
Called before a cached object is delivered to the client.
664
The vcl_deliver subroutine may terminate with one of the following
669
Deliver the object to the client.
671
.B error code [reason]
672
Return the specified error code to the client and abandon the request.
675
Restart the transaction. Increases the restart counter. If the number
676
of restarts is higher than \fImax_restarts\fP varnish emits a guru meditation
681
Called when we hit an error, either explicitly or implicitly due to
682
backend or internal errors.
684
The vcl_error subroutine may terminate by calling return with one of
685
the following keywords:
689
Deliver the error object to the client.
692
Restart the transaction. Increases the restart counter. If the number
693
of restarts is higher than \fImax_restarts\fP varnish emits a guru meditation
698
Called when VCL is discarded only after all requests have exited the VCL.
699
Typically used to clean up VMODs.
705
Normal return, VCL will be discarded.
709
If one of these subroutines is left undefined or terminates without
710
reaching a handling decision, control will be handed over to the
711
builtin default. See the EXAMPLES section for a listing of the
713
.SS Multiple subroutines
715
If multiple subroutines with the same name are defined, they are
716
concatenated in the order in which the appear in the source.
723
include "backends.vcl";
726
# in file "backends.vcl"
728
if (req.http.host ~ "(?i)example.com") {
729
set req.backend = foo;
730
} elsif (req.http.host ~ "(?i)example.org") {
731
set req.backend = bar;
737
if (client.ip ~ admin_network) {
738
if (req.http.Cache\-Control ~ "no\-cache") {
746
The builtin default subroutines are implicitly appended in this way.
749
Although subroutines take no arguments, the necessary information is
750
made available to the handler subroutines through global variables.
752
The following variables are always available:
756
The current time, in seconds since the epoch.
759
The following variables are available in backend declarations:
763
Host name or IP address of a backend.
766
Service name or port number of a backend.
769
The following variables are available while processing a request:
773
The client\(aqs IP address.
776
Identification of the client, used to load balance in the client director.
779
The host name of the server.
782
The identity of the server, as set by the \-i
783
parameter. If the \-i parameter is not passed to varnishd,
784
server.identity will be set to the name of the instance, as
785
specified by the \-n parameter.
788
The IP address of the socket on which the client connection was received.
791
The port number of the socket on which the client connection was received.
794
The request type (e.g. "GET", "HEAD").
800
The HTTP protocol version used by the client.
803
The backend to use to service the request.
805
.B req.backend.healthy
806
Whether the backend is healthy or not. Requires an active probe to be set
810
The corresponding HTTP header.
812
.B req.hash_always_miss
813
Force a cache miss for this request. If set to true Varnish will disregard
814
any existing objects and always (re)fetch from the backend.
816
.B req.hash_ignore_busy
817
Ignore any busy object during cache lookup. You would want to do
818
this if you have two server looking up content from each other to
819
avoid potential deadlocks.
822
Does the client accept the gzip transfer encoding.
825
A count of how many times this request has been restarted.
828
Boolean. Set to false to disable ESI processing regardless of any
829
value in beresp.do_esi. Defaults to true. This variable is subject
830
to change in future versions, you should avoid using it.
833
A count of how many levels of ESI requests we\(aqre currently at.
836
Set to a period to enable grace.
839
Unique ID of this request.
842
The following variables are available while preparing a backend
843
request (either for a cache miss or for pass or pipe mode):
847
The request type (e.g. "GET", "HEAD").
853
The HTTP protocol version used to talk to the server.
856
The corresponding HTTP header.
858
.B bereq.connect_timeout
859
The time in seconds to wait for a backend connection.
861
.B bereq.first_byte_timeout
862
The time in seconds to wait for the first byte from the backend. Not
863
available in pipe mode.
865
.B bereq.between_bytes_timeout
866
The time in seconds to wait between each received byte from the
867
backend. Not available in pipe mode.
870
The following variables are available after the requested object has
871
been retrieved from the backend, before it is entered into the cache. In
872
other words, they are available in vcl_fetch:
876
Deliver the object to the client directly without fetching the whole
877
object into varnish. If this request is pass\(aqed it will not be
878
stored in memory. As of Varnish Cache 3.0 the object will marked as busy
879
as it is delivered so only client can access the object.
882
Boolean. ESI\-process the object after fetching it. Defaults to
883
false. Set it to true to parse the object for ESI directives. Will
884
only be honored if req.esi is true.
887
Boolean. Gzip the object before storing it. Defaults to false.
890
Boolean. Unzip the object before storing it in the cache. Defaults
894
The HTTP protocol version used the backend replied with.
897
The HTTP status code returned by the server.
900
The HTTP status message returned by the server.
903
The object\(aqs remaining time to live, in seconds. beresp.ttl is writable.
906
Set to a period to enable grace.
909
Set to a period to enable saint mode.
911
.B beresp.backend.name
912
Name of the backend this response was fetched from.
915
IP of the backend this response was fetched from.
917
.B beresp.backend.port
918
Port of the backend this response was fetched from.
921
Set to force Varnish to save this object to a particular storage
925
After the object is entered into the cache, the following (mostly
926
read\-only) variables are available when the object has been located in
927
cache, typically in vcl_hit and vcl_deliver.
931
The HTTP protocol version used when the object was retrieved.
934
The HTTP status code returned by the server.
937
The HTTP status message returned by the server.
940
The object\(aqs remaining time to live, in seconds. obj.ttl is writable.
943
The approximate time elapsed since the object was last requests, in
947
The approximate number of times the object has been delivered. A value
948
of 0 indicates a cache miss.
951
The object\(aqs grace period in seconds. obj.grace is writable.
954
The corresponding HTTP header.
957
The following variables are available while determining the hash key
962
The hash key used to refer to an object in the cache. Used when
963
both reading from and writing to the cache.
966
The following variables are available while preparing a response to the client:
970
The HTTP protocol version to use for the response.
973
The HTTP status code that will be returned.
976
The HTTP status message that will be returned.
979
The corresponding HTTP header.
982
Values may be assigned to variables using the set keyword::
987
# Normalize the Host: header
988
if (req.http.host ~ "(?i)^(www.)?example.com$") {
989
set req.http.host = "www.example.com";
995
HTTP headers can be removed entirely using the remove keyword::
1000
# Don\(aqt cache cookies
1001
remove beresp.http.Set\-Cookie;
1005
.SS Grace and saint mode
1007
If the backend takes a long time to generate an object there is a risk
1008
of a thread pile up. In order to prevent this you can enable \fIgrace\fP.
1009
This allows varnish to serve an expired version of the object while a
1010
fresh object is being generated by the backend.
1012
The following vcl code will make Varnish serve expired objects. All
1013
object will be kept up to two minutes past their expiration time or a
1014
fresh object is generated.:
1022
set beresp.grace = 2m;
1027
Saint mode is similar to grace mode and relies on the same
1028
infrastructure but functions differently. You can add VCL code to
1029
vcl_fetch to see whether or not you \fIlike\fP the response coming from
1030
the backend. If you find that the response is not appropriate you can
1031
set beresp.saintmode to a time limit and call \fIrestart\fP. Varnish will
1032
then retry other backends to try to fetch the object again.
1034
If there are no more backends or if you hit \fImax_restarts\fP and we have
1035
an object that is younger than what you set beresp.saintmode to be
1036
Varnish will serve the object, even if it is stale.
1039
The following code is the equivalent of the default configuration with
1040
the backend address set to "backend.example.com" and no backend port
1046
.host = "backend.example.com";
1055
* Copyright (c) 2006 Verdens Gang AS
1056
* Copyright (c) 2006\-2011 Varnish Software AS
1057
* All rights reserved.
1059
* Author: Poul\-Henning Kamp <phk@phk.freebsd.dk>
1061
* Redistribution and use in source and binary forms, with or without
1062
* modification, are permitted provided that the following conditions
1064
* 1. Redistributions of source code must retain the above copyright
1065
* notice, this list of conditions and the following disclaimer.
1066
* 2. Redistributions in binary form must reproduce the above copyright
1067
* notice, this list of conditions and the following disclaimer in the
1068
* documentation and/or other materials provided with the distribution.
1070
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS \(ga\(gaAS IS\(aq\(aq AND
1071
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1072
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1073
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE
1074
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1075
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1076
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
1077
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
1078
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
1079
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
1080
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1082
* The default VCL code.
1084
* NB! You do NOT need to copy & paste all of these functions into your
1085
* own vcl code, if you do not provide a definition of one of these
1086
* functions, the compiler will automatically fall back to the default
1087
* code from this file.
1089
* This code will be prefixed with a backend declaration built from the
1094
if (req.restarts == 0) {
1095
if (req.http.x\-forwarded\-for) {
1096
set req.http.X\-Forwarded\-For =
1097
req.http.X\-Forwarded\-For + ", " + client.ip;
1099
set req.http.X\-Forwarded\-For = client.ip;
1102
if (req.request != "GET" &&
1103
req.request != "HEAD" &&
1104
req.request != "PUT" &&
1105
req.request != "POST" &&
1106
req.request != "TRACE" &&
1107
req.request != "OPTIONS" &&
1108
req.request != "DELETE") {
1109
/* Non\-RFC2616 or CONNECT which is weird. */
1112
if (req.request != "GET" && req.request != "HEAD") {
1113
/* We only deal with GET and HEAD by default */
1116
if (req.http.Authorization || req.http.Cookie) {
1117
/* Not cacheable by default */
1124
# Note that only the first request to the backend will have
1125
# X\-Forwarded\-For set. If you use X\-Forwarded\-For and want to
1126
# have it set for all requests, make sure to have:
1127
# set bereq.http.connection = "close";
1128
# here. It is not set by default as it might break some broken web
1129
# applications, like IIS with NTLM authentication.
1139
if (req.http.host) {
1140
hash_data(req.http.host);
1142
hash_data(server.ip);
1156
if (beresp.ttl <= 0s ||
1157
beresp.http.Set\-Cookie ||
1158
beresp.http.Vary == "*") {
1160
* Mark as "Hit\-For\-Pass" for the next 2 minutes
1162
set beresp.ttl = 120 s;
1163
return (hit_for_pass);
1173
set obj.http.Content\-Type = "text/html; charset=utf\-8";
1174
set obj.http.Retry\-After = "5";
1176
<?xml version="1.0" encoding="utf\-8"?>
1177
<!DOCTYPE html PUBLIC "\-//W3C//DTD XHTML 1.0 Strict//EN"
1178
"http://www.w3.org/TR/xhtml1/DTD/xhtml1\-strict.dtd">
1181
<title>"} + obj.status + " " + obj.response + {"</title>
1184
<h1>Error "} + obj.status + " " + obj.response + {"</h1>
1185
<p>"} + obj.response + {"</p>
1186
<h3>Guru Meditation:</h3>
1187
<p>XID: "} + req.xid + {"</p>
1189
<p>Varnish cache server</p>
1207
The following example shows how to support multiple sites running on
1208
separate backends in the same Varnish instance, by selecting backends
1209
based on the request URL::
1214
.host = "www.example.com";
1219
.host = "images.example.com";
1224
if (req.http.host ~ "(?i)^(www.)?example.com$") {
1225
set req.http.host = "www.example.com";
1226
set req.backend = www;
1227
} elsif (req.http.host ~ "(?i)^images.example.com$") {
1228
set req.backend = images;
1230
error 404 "Unknown virtual host";
1234
The following snippet demonstrates how to force a minimum TTL for
1235
all documents. Note that this is not the same as setting the
1236
default_ttl run\-time parameter, as that only affects document for
1237
which the backend did not specify a TTL:::
1239
import std; # needed for std.log
1242
if (beresp.ttl < 120s) {
1243
std.log("Adjusting TTL");
1244
set beresp.ttl = 120s;
1250
The following snippet demonstrates how to force Varnish to cache
1251
documents even when cookies are present::
1256
if (req.request == "GET" && req.http.cookie) {
1262
if (beresp.http.Set\-Cookie) {
1269
The following code implements the HTTP PURGE method as used by Squid
1270
for object invalidation::
1280
if (req.request == "PURGE") {
1281
if (!client.ip ~ purge) {
1282
error 405 "Not allowed.";
1289
if (req.request == "PURGE") {
1291
error 200 "Purged.";
1296
if (req.request == "PURGE") {
1298
error 200 "Purged.";
1312
VCL was developed by Poul\-Henning Kamp in cooperation with Verdens
1313
Gang AS, Redpill Linpro and Varnish Software. This manual page was
1314
written by Dag\-Erling Smørgrav and later edited by Poul\-Henning Kamp
1318
This document is licensed under the same license as Varnish
1319
itself. See LICENSE for details.
1322
Copyright (c) 2006 Verdens Gang AS
1324
Copyright (c) 2006\-2011 Varnish Software AS
1327
Dag-Erling Smørgrav, Poul-Henning Kamp, Kristian Lyngstøl, Per Buer
1328
.\" Generated by docutils manpage writer.