Commit f8dd5ccc authored by Tollef Fog Heen's avatar Tollef Fog Heen

Documentation updates

Update docs for purge → ban rename plus various typos and grammatical
errors.
parent a7c18717
...@@ -33,11 +33,11 @@ How... ...@@ -33,11 +33,11 @@ How...
That depends on pretty much everything. That depends on pretty much everything.
I think our best current guidance is that you go for a cost-effective I think our best current guidance is that you go for a cost-effective
RAM configuration, something like 1-16GB, and a SSD disk. RAM configuration, something like 1-16GB, and an SSD.
Unless you positively know that you will need it, there is Unless you positively know that you will need it, there is
little point in spendng a fortune on a hand-sewn motherboard little point in spending a fortune on a hand-sewn motherboard
that can fit several TB in special RAM blocks, rivetet together that can fit several TB in special RAM blocks, riveted together
by leftover watch-makers in Switzerland. by leftover watch-makers in Switzerland.
On the other hand, if you plot your traffic in Gb/s, you probably On the other hand, if you plot your traffic in Gb/s, you probably
...@@ -65,14 +65,14 @@ Refreshing is often called `purging <http://dictionary.reference.com/browse/PURG ...@@ -65,14 +65,14 @@ Refreshing is often called `purging <http://dictionary.reference.com/browse/PURG
From the command line you can write:: From the command line you can write::
url.purge ^/$ ban.url ^/$
to purge your / document. As you might see url.purge takes an `regular expression <http://en.wikipedia.org/wiki/Regular_expression>`_ to ban your / document. As you might see ban.url takes an `regular expression <http://en.wikipedia.org/wiki/Regular_expression>`_
as its argument. Hence the ``^`` and ``$`` at the front and end. If the ``^`` is ommited, all the documents ending in a ``/`` in the cache would be deleted. as its argument. Hence the ``^`` and ``$`` at the front and end. If the ``^`` is omitted, all the documents ending in a ``/`` in the cache would be deleted.
So to delete all the documents in the cache, write:: So to delete all the documents in the cache, write::
url.purge .* ban.url .
at the command line. at the command line.
...@@ -96,15 +96,15 @@ At the shell command line, type:: ...@@ -96,15 +96,15 @@ At the shell command line, type::
**How can I rewrite URLS before they are sent to the backend?** **How can I rewrite URLS before they are sent to the backend?**
You can use the ``regsub()`` function to do this. Here's an example for zope, to rewrite URL's for the virtualhostmonster:: You can use the ``regsub()`` function to do this. Here's an example for zope, to rewrite URLs for the virtualhostmonster::
if (req.http.host ~ "^(www.)?example.com") { if (req.http.host ~ "^(www.)?example.com") {
set req.url = regsub(req.url, "^", "/VirtualHostBase/http/example.com:80/Sites/example.com/VirtualHostRoot"); set req.url = regsub(req.url, "^", "/VirtualHostBase/http/example.com:80/Sites/example.com/VirtualHostRoot");
} }
**I have a site with many hostnames, how do I keep them from multiplying the cache?** **I have a site with many host names, how do I keep them from multiplying the cache?**
You can do this by normalizing the ``Host`` header for all your hostnames. Here's a VCL example:: You can do this by normalizing the ``Host`` header for all your host names. Here's a VCL example::
if (req.http.host ~ "^(www.)?example.com") { if (req.http.host ~ "^(www.)?example.com") {
set req.http.host = "example.com"; set req.http.host = "example.com";
...@@ -120,7 +120,7 @@ You can use the ``bereq`` object for altering requests going to the backend, but ...@@ -120,7 +120,7 @@ You can use the ``bereq`` object for altering requests going to the backend, but
**How do I force the backend to send Vary headers?** **How do I force the backend to send Vary headers?**
We have anectdotal evidence of non-RFC2616 compliant backends, which support content negotiation, but which do not emit a Vary header, unless the request contains Accept headers. We have anecdotal evidence of non-RFC2616 compliant backends, which support content negotiation, but which do not emit a Vary header, unless the request contains Accept headers.
It may be appropriate to send no-op Accept headers to trick the backend into sending us the Vary header. It may be appropriate to send no-op Accept headers to trick the backend into sending us the Vary header.
...@@ -177,8 +177,8 @@ Where... ...@@ -177,8 +177,8 @@ Where...
**Can I find varnish for my operating system?** **Can I find varnish for my operating system?**
We know that Varnish has been packaged for Debian, Ubuntu, RHEL, We know that Varnish has been packaged for Debian, Ubuntu, RHEL,
Centos, (Open)SuSE, Gentoo and FreeBSD, possibly more. Check whatever CentOS, (Open)SUSE, Gentoo and FreeBSD, possibly more. Check whatever
packagemanager you use. Or read :ref:`Installing Varnish on your computer <install-doc>`. package manager you use. Or read :ref:`Installing Varnish on your computer <install-doc>`.
Can I... Can I...
======== ========
...@@ -211,7 +211,7 @@ Yes, as long as you give them different TCP ports and different ``-n`` ...@@ -211,7 +211,7 @@ Yes, as long as you give them different TCP ports and different ``-n``
arguments, you will be fine. arguments, you will be fine.
**Can I cache multiple vhosts with one Varnish?** **Can I cache multiple virtual hosts with one Varnish?**
Yes, that works right out of the box. Yes, that works right out of the box.
...@@ -228,7 +228,7 @@ Besides, the output is a lot less useful than you might think. ...@@ -228,7 +228,7 @@ Besides, the output is a lot less useful than you might think.
Not at present, and while we keep an eye on this, there are no Not at present, and while we keep an eye on this, there are no
current plans to add HTTPS support, until we can find a way where current plans to add HTTPS support, until we can find a way where
it adds significant value, relative to running a stand-alone it adds significant value, relative to running a stand-alone
HTTPS proxy such as ngnix or pound. HTTPS proxy such as nginx or pound.
**Can Varnish load balance between multiple backends?** **Can Varnish load balance between multiple backends?**
...@@ -259,10 +259,10 @@ There are 2 common reasons for this: ...@@ -259,10 +259,10 @@ There are 2 common reasons for this:
**Why are regular expressions case-sensitive?** **Why are regular expressions case-sensitive?**
Some HTTP headers, such as ``Host:`` and ``Location:`` Some HTTP headers, such as ``Host:`` and ``Location:`` contain fully
contain FQDN's which by definition is not case-sensitive. Other qualified domain names, which by definition is not case-sensitive.
HTTP headers are case-sensitive, most notably the URLs. Therefore Other HTTP headers are case-sensitive, most notably the URLs.
a "one size fits all" solution is not possible. Therefore a "one size fits all" solution is not possible.
In previous releases, we used the POSIX regular expressions In previous releases, we used the POSIX regular expressions
supplied with the operating system, and decided, because the supplied with the operating system, and decided, because the
...@@ -272,12 +272,12 @@ they should not be case-sensitive. ...@@ -272,12 +272,12 @@ they should not be case-sensitive.
From version 2.1.0 and forward, we use PCRE regular expressions, From version 2.1.0 and forward, we use PCRE regular expressions,
where it *is* possible to control case-sensitivity in the where it *is* possible to control case-sensitivity in the
individual regular expressions, so we decided that it would individual regular expressions, so we decided that it would
probably confuse people if we made the default case-insentive. probably confuse people if we made the default case-insensitive.
(We promise not to change our minds about this again.) (We promise not to change our minds about this again.)
To make a PCRE regex case insensitive, put ``(?i)`` at the start:: To make a PCRE regex case insensitive, put ``(?i)`` at the start::
if (req.http.host ~ "?iexample.com$") { if (req.http.host ~ "(?i)example.com$") {
... ...
} }
...@@ -295,7 +295,7 @@ See the `PCRE man pages <http://www.pcre.org/pcre.txt>`_ for more information. ...@@ -295,7 +295,7 @@ See the `PCRE man pages <http://www.pcre.org/pcre.txt>`_ for more information.
**Why does the ``Via:`` header say 1.1 in Varnish 2.1.x?** **Why does the ``Via:`` header say 1.1 in Varnish 2.1.x?**
The number in the ``Via:`` header is the HTTP protocol version The number in the ``Via:`` header is the HTTP protocol version
supported/applied, not the softwares version number. supported/applied, not the software's version number.
**Why did you call it *Varnish*?** **Why did you call it *Varnish*?**
...@@ -336,14 +336,14 @@ Varnish has a feature called **hit for pass**, which is used when Varnish gets a ...@@ -336,14 +336,14 @@ Varnish has a feature called **hit for pass**, which is used when Varnish gets a
* Worker returns object to varnish which turns out to be non-cacheable. * Worker returns object to varnish which turns out to be non-cacheable.
* Client 2..N are now given the **hit for pass** object instructing them to go to the backend * Client 2..N are now given the **hit for pass** object instructing them to go to the backend
The **hit for pass** object will stay cached for the duration of it's ttl. This means that subsequent clients requesting /foo will be sent straight to the backend as long as the **hit for pass** object exists. The **hit for pass** object will stay cached for the duration of its ttl. This means that subsequent clients requesting /foo will be sent straight to the backend as long as the **hit for pass** object exists.
The :command:`varnishstat` can tell you how many **hit for pass** objects varnish has served. You can lower the ttl for such an object if you are sure this is needed, using the following logic:: The :command:`varnishstat` can tell you how many **hit for pass** objects varnish has served. You can lower the ttl for such an object if you are sure this is needed, using the following logic::
sub vcl_fetch { sub vcl_fetch {
if (!obj.cacheable) { if (!obj.cacheable) {
# Limit the lifetime of all 'hit for pass' objects to 10 seconds # Limit the lifetime of all 'hit for pass' objects to 10 seconds
obj.ttl = 10s; obj.ttl = 10s;
pass; return(hit_for_pass);
} }
} }
...@@ -120,7 +120,7 @@ ban.url regexp ...@@ -120,7 +120,7 @@ ban.url regexp
Immediately invalidate all documents whose URL matches the Immediately invalidate all documents whose URL matches the
specified regular expression. Please note that the Host part of specified regular expression. Please note that the Host part of
the URL is ignored, so if you have several virtual hosts all of the URL is ignored, so if you have several virtual hosts all of
them will be purged. Use *ban* to specify a complete ban if you them will be banned. Use *ban* to specify a complete ban if you
need to narrow it down. need to narrow it down.
quit quit
...@@ -280,16 +280,16 @@ EXAMPLES ...@@ -280,16 +280,16 @@ EXAMPLES
======== ========
Simple example: All requests where req.url exactly matches the string Simple example: All requests where req.url exactly matches the string
/news are purged from the cache::: /news are banned from the cache:::
req.url == "/news" req.url == "/news"
Example: Purge all documents where the name does not end with ".ogg", Example: Ban all documents where the name does not end with ".ogg",
and where the size of the object is greater than 10 megabytes::: and where the size of the object is greater than 10 megabytes:::
req.url !~ "\.ogg$" && obj.size > 10MB req.url !~ "\.ogg$" && obj.size > 10MB
Example: Purge all documents where the serving host is "example.com" Example: Ban all documents where the serving host is "example.com"
or "www.example.com", and where the Set-Cookie header received from or "www.example.com", and where the Set-Cookie header received from
the backend contains "USERID=1663"::: the backend contains "USERID=1663":::
......
...@@ -323,8 +323,8 @@ regsub(str, regex, sub) ...@@ -323,8 +323,8 @@ regsub(str, regex, sub)
regsuball(str, regex, sub) regsuball(str, regex, sub)
As regsuball() but this replaces all occurrences. As regsuball() but this replaces all occurrences.
purge_url(regex) ban_url(regex)
Purge all objects in cache whose URLs match regex. Ban all objects in cache whose URLs match regex.
Subroutines Subroutines
~~~~~~~~~~~ ~~~~~~~~~~~
...@@ -523,7 +523,7 @@ Example::: ...@@ -523,7 +523,7 @@ Example:::
# in file "main.vcl" # in file "main.vcl"
include "backends.vcl"; include "backends.vcl";
include "purge.vcl"; include "ban.vcl";
# in file "backends.vcl" # in file "backends.vcl"
sub vcl_recv { sub vcl_recv {
...@@ -534,11 +534,11 @@ Example::: ...@@ -534,11 +534,11 @@ Example:::
} }
} }
# in file "purge.vcl" # in file "ban.vcl"
sub vcl_recv { sub vcl_recv {
if (client.ip ~ admin_network) { if (client.ip ~ admin_network) {
if (req.http.Cache-Control ~ "no-cache") { if (req.http.Cache-Control ~ "no-cache") {
purge_url(req.url); ban_url(req.url);
} }
} }
} }
...@@ -858,14 +858,15 @@ for object invalidation::: ...@@ -858,14 +858,15 @@ for object invalidation:::
sub vcl_hit { sub vcl_hit {
if (req.request == "PURGE") { if (req.request == "PURGE") {
set obj.ttl = 0s; purge;
error 200 "Purged."; error 200 "Purged.";
} }
} }
sub vcl_miss { sub vcl_miss {
if (req.request == "PURGE") { if (req.request == "PURGE") {
error 404 "Not in cache."; purge;
error 200 "Purged.";
} }
} }
......
.. _tutorial-purging: .. _tutorial-purging:
Purging and banning =====================
------------------- Purging and banning
=====================
One of the most effective way of increasing your hit ratio is to One of the most effective way of increasing your hit ratio is to
increase the time-to-live (ttl) of your objects. But, as you're aware increase the time-to-live (ttl) of your objects. But, as you're aware
...@@ -14,7 +15,7 @@ bans. First, let me explain the HTTP purges. ...@@ -14,7 +15,7 @@ bans. First, let me explain the HTTP purges.
HTTP Purges HTTP Purges
~~~~~~~~~~~ ===========
An HTTP purge is similar to an HTTP GET request, except that the An HTTP purge is similar to an HTTP GET request, except that the
*method* is PURGE. Actually you can call the method whatever you'd *method* is PURGE. Actually you can call the method whatever you'd
...@@ -40,17 +41,15 @@ following VCL in place:: ...@@ -40,17 +41,15 @@ following VCL in place::
sub vcl_hit { sub vcl_hit {
if (req.request == "PURGE") { if (req.request == "PURGE") {
# Note that setting ttl to 0 is magical. purge;
# the object is zapped from cache.
set obj.ttl = 0s;
error 200 "Purged."; error 200 "Purged.";
} }
} }
sub vcl_miss { sub vcl_miss {
if (req.request == "PURGE") { if (req.request == "PURGE") {
purge;
error 404 "Not in cache."; error 200 "Purged.";
} }
} }
...@@ -60,23 +59,17 @@ its cache. It will either hit an object or miss it and so the ...@@ -60,23 +59,17 @@ its cache. It will either hit an object or miss it and so the
corresponding subroutine is called. In vcl_hit the object that is corresponding subroutine is called. In vcl_hit the object that is
stored in cache is available and we can set the TTL. stored in cache is available and we can set the TTL.
So for vg.no to invalidate their front page they would call out to So for example.com to invalidate their front page they would call out
Varnish like this:: to Varnish like this::
PURGE / HTTP/1.0 PURGE / HTTP/1.0
Host: vg.no Host: example.com
And Varnish would then discard the front page. If there are several And Varnish would then discard the front page. This will remove all
variants of the same URL in the cache however, only the matching variants as defined by Vary.
variant will be purged. To purge a gzip variant of the same page the
request would have to look like this::
PURGE / HTTP/1.0
Host: vg.no
Accept-Encoding: gzip
Bans Bans
~~~~ ====
There is another way to invalidate content. Bans. You can think of There is another way to invalidate content. Bans. You can think of
bans as a sort of a filter. You *ban* certain content from being bans as a sort of a filter. You *ban* certain content from being
...@@ -84,10 +77,10 @@ served from your cache. You can ban content based on any metadata we ...@@ -84,10 +77,10 @@ served from your cache. You can ban content based on any metadata we
have. have.
Support for bans is built into Varnish and available in the CLI Support for bans is built into Varnish and available in the CLI
interface. For VG to ban every png object belonging on vg.no they could interface. For VG to ban every png object belonging on example.com
issue:: they could issue::
purge req.http.host == "vg.no" && req.http.url ~ "\.png$" ban req.http.host == "example.com" && req.http.url ~ "\.png$"
Quite powerful, really. Quite powerful, really.
...@@ -104,7 +97,7 @@ You can also add bans to Varnish via HTTP. Doing so requires a bit of VCL:: ...@@ -104,7 +97,7 @@ You can also add bans to Varnish via HTTP. Doing so requires a bit of VCL::
if (!client.ip ~ purge) { if (!client.ip ~ purge) {
error 405 "Not allowed."; error 405 "Not allowed.";
} }
purge("req.http.host == " req.http.host ban("req.http.host == " req.http.host
"&& req.url == " req.url); "&& req.url == " req.url);
# Throw a synthetic page so the # Throw a synthetic page so the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment