AWS Book by Fatah Ikram
Author:Fatah, Ikram
Language: eng
Format: epub
Published: 2016-03-01T16:00:00+00:00
8.3. Editing the Varnish VCL File
Varnish’s settings for how it handles your site(s) is stored in another file. It is found in /etc/varnish/default.vcl. By default, the default.vcl file has only four lines of active configuration:
backend default {
.host = "127.0.0.1";
.port = "8080";
}
The .host setting tells Varnish where Apache is located, is it on the same server or a different server? The IP address 127.0.01 refers to the server itself, which tells Varnish that Apache is on the same server as itself.
The .port setting tells Varnish where to connect to Apache internally. This is different from the port setting of the previous section.
We will need to set Apache to use the 8080 port so that Varnish can find it and connect to it. We will do that in a later section.
Everything else you see in the file has been “commented out” by preceding the lines with a # so that they do not do anything until you remove the preceding #.
To tell Varnish to store a cached webpage for one hour before it requests a new version from Apache, you’d use the following lines:
sub vcl_fetch {
set beresp.ttl = 1h;
}
That is TTL, not TT1.
You might have two websites, one of which is updated every ten minutes, while another is updated only once every a few days. In such a case, you can tell Varnish to use different settings for each website. Below, I am telling Varnish to store cached webpages for example.com for two days, while telling it to store cached webpages for example2.com for only 10 minutes. If there is a third website, it will use the default 1h (one hour) setting on the second line.
sub vcl_fetch {
set beresp.ttl = 1h;
if (req.http.host ~ "(www\.)?(example)\.com") {
set beresp.ttl = 2d;
}
if (req.http.host ~ "(www\.)?(example2)\.com") {
set beresp.ttl = 10m;
}
}
It is also important to add the following lines to your vcl_fetch settings so that Varnish does not cache error pages that happen when Apache temporarily goes down or fails to deliver a page. If Varnish caches such error pages, then the next time someone tries to visit the page, Varnish serves them the cached error page, which is a pretty bad thing, since the actual page might be accessible by then while your site’s visitors keep seeing an old error page.
To prevent such a situation, add these three lines to the vcl_fetch function:
if ( beresp.status >= 500 ) {
set beresp.ttl = 0s;
}
The first line is saying if the webpage has a status of 500 or more (which happens when Apache is down, or when there is a syntax error in your PHP code), do the following. The second line is what Varnish will do, which is keep the webpage in cache for 0 seconds, meaning that the next time someone tries to visit that webpage, Varnish will request it again from Apache, and hopefully this time is Apache is up, or the PHP syntax error has been corrected. If not, Varnish will continue requesting the webpage again and again from Apache as people visit the
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(15032)
The Mikado Method by Ola Ellnestam Daniel Brolund(12292)
Hello! Python by Anthony Briggs(12183)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(11550)
Dependency Injection in .NET by Mark Seemann(11336)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10530)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(10150)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(9811)
Grails in Action by Glen Smith Peter Ledbrook(9479)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(9045)
Hit Refresh by Satya Nadella(9040)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(9032)
The Kubernetes Operator Framework Book by Michael Dame(8474)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(8437)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8299)
Robo-Advisor with Python by Aki Ranin(8252)
Practical Computer Architecture with Python and ARM by Alan Clements(8225)
Implementing Enterprise Observability for Success by Manisha Agrawal and Karun Krishnannair(8195)
Building Low Latency Applications with C++ by Sourav Ghosh(8099)