Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
8931bc07
Commit
8931bc07
authored
Apr 16, 2012
by
Per Buer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
:: need to be on a separate line in RST.
parent
9a1b232b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
22 deletions
+44
-22
vcl.rst
doc/sphinx/reference/vcl.rst
+44
-22
No files found.
doc/sphinx/reference/vcl.rst
View file @
8931bc07
...
@@ -96,14 +96,16 @@ file as a quoted string.
...
@@ -96,14 +96,16 @@ file as a quoted string.
Backend declarations
Backend declarations
--------------------
--------------------
A backend declaration creates and initializes a named backend object::
A backend declaration creates and initializes a named backend object:
::
backend www {
backend www {
.host = "www.example.com";
.host = "www.example.com";
.port = "http";
.port = "http";
}
}
The backend object can later be used to select a backend at request time::
The backend object can later be used to select a backend at request time:
::
if (req.http.host ~ "(?i)^(www.)?example.com$") {
if (req.http.host ~ "(?i)^(www.)?example.com$") {
set req.backend = www;
set req.backend = www;
...
@@ -118,7 +120,8 @@ backend connection, .first_byte_timeout for the time to wait for the
...
@@ -118,7 +120,8 @@ backend connection, .first_byte_timeout for the time to wait for the
first byte from the backend and .between_bytes_timeout for time to
first byte from the backend and .between_bytes_timeout for time to
wait between each received byte.
wait between each received byte.
These can be set in the declaration like this::
These can be set in the declaration like this:
::
backend www {
backend www {
.host = "www.example.com";
.host = "www.example.com";
...
@@ -145,7 +148,8 @@ be used.
...
@@ -145,7 +148,8 @@ be used.
There are several types of directors. The different director types
There are several types of directors. The different director types
use different algorithms to choose which backend to use.
use different algorithms to choose which backend to use.
Configuring a director may look like this::
Configuring a director may look like this:
::
director b2 random {
director b2 random {
.retries = 5;
.retries = 5;
...
@@ -226,7 +230,8 @@ The DNS director
...
@@ -226,7 +230,8 @@ The DNS director
~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~
The DNS director can use backends in two different ways. Either like the
The DNS director can use backends in two different ways. Either like the
random or round-robin director or using .list::
random or round-robin director or using .list:
::
director directorname dns {
director directorname dns {
.list = {
.list = {
...
@@ -266,7 +271,8 @@ considers them in the order in which they are listed in its definition.
...
@@ -266,7 +271,8 @@ considers them in the order in which they are listed in its definition.
The fallback director does not take any options.
The fallback director does not take any options.
An example of a fallback director::
An example of a fallback director:
::
director b3 fallback {
director b3 fallback {
{ .backend = www1; }
{ .backend = www1; }
...
@@ -312,7 +318,8 @@ Probes take the following parameters:
...
@@ -312,7 +318,8 @@ Probes take the following parameters:
Default is 2 seconds.
Default is 2 seconds.
A backend with a probe can be defined like this, together with the
A backend with a probe can be defined like this, together with the
backend or director::
backend or director:
::
backend www {
backend www {
.host = "www.example.com";
.host = "www.example.com";
...
@@ -326,7 +333,8 @@ backend or director::
...
@@ -326,7 +333,8 @@ backend or director::
}
}
}
}
Or it can be defined separately and then referenced::
Or it can be defined separately and then referenced:
::
probe healthcheck {
probe healthcheck {
.url = "/status.cgi";
.url = "/status.cgi";
...
@@ -347,7 +355,8 @@ Or it can be defined separately and then referenced::
...
@@ -347,7 +355,8 @@ Or it can be defined separately and then referenced::
If you have many backends this can simplify the config a lot.
If you have many backends this can simplify the config a lot.
It is also possible to specify the raw HTTP request::
It is also possible to specify the raw HTTP request:
::
probe rawprobe {
probe rawprobe {
# NB: \r\n automatically inserted after each string!
# NB: \r\n automatically inserted after each string!
...
@@ -361,7 +370,8 @@ ACLs
...
@@ -361,7 +370,8 @@ ACLs
----
----
An ACL declaration creates and initializes a named access control list
An ACL declaration creates and initializes a named access control list
which can later be used to match client addresses::
which can later be used to match client addresses:
::
acl local {
acl local {
"localhost"; // myself
"localhost"; // myself
...
@@ -375,7 +385,8 @@ if it is preceded by a negation mark, it will reject any address it is
...
@@ -375,7 +385,8 @@ if it is preceded by a negation mark, it will reject any address it is
compared to, which may not be what you intended. If the entry is
compared to, which may not be what you intended. If the entry is
enclosed in parentheses, however, it will simply be ignored.
enclosed in parentheses, however, it will simply be ignored.
To match an IP address against an ACL, simply use the match operator::
To match an IP address against an ACL, simply use the match operator:
::
if (client.ip ~ local) {
if (client.ip ~ local) {
return (pipe);
return (pipe);
...
@@ -390,7 +401,8 @@ PCRE(3) man page.
...
@@ -390,7 +401,8 @@ PCRE(3) man page.
To send flags to the PCRE engine, such as to turn on *case
To send flags to the PCRE engine, such as to turn on *case
insensitivity* add the flag within parens following a question mark,
insensitivity* add the flag within parens following a question mark,
like this::
like this:
::
if (req.http.host ~ "(?i)example.com$") {
if (req.http.host ~ "(?i)example.com$") {
...
...
...
@@ -424,7 +436,8 @@ ban_url(regex)
...
@@ -424,7 +436,8 @@ ban_url(regex)
Subroutines
Subroutines
~~~~~~~~~~~
~~~~~~~~~~~
A subroutine is used to group code for legibility or reusability::
A subroutine is used to group code for legibility or reusability:
::
sub pipe_if_local {
sub pipe_if_local {
if (client.ip ~ local) {
if (client.ip ~ local) {
...
@@ -646,7 +659,8 @@ appear in the source.
...
@@ -646,7 +659,8 @@ appear in the source.
The default versions distributed with Varnish will be implicitly
The default versions distributed with Varnish will be implicitly
concatenated as a last resort at the end.
concatenated as a last resort at the end.
Example::
Example:
::
# in file "main.vcl"
# in file "main.vcl"
include "backends.vcl";
include "backends.vcl";
...
@@ -893,7 +907,8 @@ resp.response
...
@@ -893,7 +907,8 @@ resp.response
resp.http.header
resp.http.header
The corresponding HTTP header.
The corresponding HTTP header.
Values may be assigned to variables using the set keyword::
Values may be assigned to variables using the set keyword:
::
sub vcl_recv {
sub vcl_recv {
# Normalize the Host: header
# Normalize the Host: header
...
@@ -902,7 +917,8 @@ Values may be assigned to variables using the set keyword::
...
@@ -902,7 +917,8 @@ Values may be assigned to variables using the set keyword::
}
}
}
}
HTTP headers can be removed entirely using the remove keyword::
HTTP headers can be removed entirely using the remove keyword:
::
sub vcl_fetch {
sub vcl_fetch {
# Don't cache cookies
# Don't cache cookies
...
@@ -919,7 +935,8 @@ fresh object is being generated by the backend.
...
@@ -919,7 +935,8 @@ fresh object is being generated by the backend.
The following vcl code will make Varnish serve expired objects. All
The following vcl code will make Varnish serve expired objects. All
object will be kept up to two minutes past their expiration time or a
object will be kept up to two minutes past their expiration time or a
fresh object is generated.::
fresh object is generated.
::
sub vcl_recv {
sub vcl_recv {
set req.grace = 2m;
set req.grace = 2m;
...
@@ -944,7 +961,8 @@ EXAMPLES
...
@@ -944,7 +961,8 @@ EXAMPLES
The following code is the equivalent of the default configuration with
The following code is the equivalent of the default configuration with
the backend address set to "backend.example.com" and no backend port
the backend address set to "backend.example.com" and no backend port
specified::
specified:
::
backend default {
backend default {
.host = "backend.example.com";
.host = "backend.example.com";
...
@@ -956,7 +974,8 @@ specified::
...
@@ -956,7 +974,8 @@ specified::
The following example shows how to support multiple sites running on
The following example shows how to support multiple sites running on
separate backends in the same Varnish instance, by selecting backends
separate backends in the same Varnish instance, by selecting backends
based on the request URL::
based on the request URL:
::
backend www {
backend www {
.host = "www.example.com";
.host = "www.example.com";
...
@@ -982,7 +1001,8 @@ based on the request URL::
...
@@ -982,7 +1001,8 @@ based on the request URL::
The following snippet demonstrates how to force a minimum TTL for
The following snippet demonstrates how to force a minimum TTL for
all documents. Note that this is not the same as setting the
all documents. Note that this is not the same as setting the
default_ttl run-time parameter, as that only affects document for
default_ttl run-time parameter, as that only affects document for
which the backend did not specify a TTL::
which the backend did not specify a TTL:
::
import std; # needed for std.log
import std; # needed for std.log
...
@@ -994,7 +1014,8 @@ which the backend did not specify a TTL::
...
@@ -994,7 +1014,8 @@ which the backend did not specify a TTL::
}
}
The following snippet demonstrates how to force Varnish to cache
The following snippet demonstrates how to force Varnish to cache
documents even when cookies are present::
documents even when cookies are present:
::
sub vcl_recv {
sub vcl_recv {
if (req.request == "GET" && req.http.cookie) {
if (req.request == "GET" && req.http.cookie) {
...
@@ -1009,7 +1030,8 @@ documents even when cookies are present::
...
@@ -1009,7 +1030,8 @@ documents even when cookies are present::
}
}
The following code implements the HTTP PURGE method as used by Squid
The following code implements the HTTP PURGE method as used by Squid
for object invalidation::
for object invalidation:
::
acl purge {
acl purge {
"localhost";
"localhost";
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment