Varnish is a web accelerator (reverse proxy), which provides relief for the actual web server (the backend). It has been designed from the ground up just for this use, unlike traditional proxies (eg Squid).

The project website can be found here: http://www.varnish-cache.org

installation

Varnish is part of Debian (Wheezy: Version 3.0.2) and Ubuntu (Trusty: Version 3.0.5). Meanwhile, there is Varnish 4.x, which is currently not included in any stable Debian / Ubuntu version.

To install the 3.x version from the Debian / Ubuntu repository, proceed as follows:

apt-get install varnish

If you want a newer version (4.x) for Debian / Ubuntu, you can also directly integrate the repository of varnish-cache.org. The instructions can be found here:

For RedHat Enterprise Linux (RHEL / CentOS), there are packages in the Extra Packages for Enterprise Linux (EPEL) repository at http://fedoraproject.org/wiki/EPEL . For RHEL 7, a Varnish 4.x version is available in the EPEL Repository. http://dl.fedoraproject.org/pub/epel/7/x86_64/repoview/varnish.html

More details about the installation can be found here:

configuration

There is a separate configuration language called VCL (Varnish Configuration Language). With this the Varnish cache is configured, then translated into binary code and executed for the incoming Web requests. Normally one finds the standard configuration in /etc/varnish/default.vcl. If the website to be accelerated uses cookies, the default configuration of Varnish must be adjusted in any case. Only then is data cached by Varnish. For further understanding of VCL, the following document should be read: https://www.varnish-cache.org/docs/3.0/tutorial/vcl.html

Even though a page contains mostly dynamic content, image, stylesheet and javascript files can almost always be cached. In addition, dynamic pages can also be cached. This works with Edge Side Includes (ESI). This will set specific “<esi: include …”> tags, which content of a website can change dynamically and how long they should be cached.

The Varnish Daemon itself is usually adapted via its own distribution-specific file.

  • Debian / Ubuntu: /etc/default/varnish
  • RHEL / CentOS: /etc/sysconfig/varnish

Among other things, it specifies on which IP and port the Varnish should listen and whether volatile memory (type “malloc”) or persistent memory (type “file”) should be used.

To get started, the Varnish Tutorial is available at: http://www.varnish-cache.org/docs/3.0/tutorial/index.html

More in-depth details can be found in the wiki: http://www.varnish-cache.org/wiki/

statistics

Varnish includes some statistics tools.

Using varnishhist you can graphically display how many requests show cache hits and how many are passed on to the backend. You can also see the respective response times in seconds on the x-axis (eg: 1e-1 -> 0.37 seconds, 1e-5 -> 0.0067 seconds)

Varnishhist.png

Using varnishstat you can display detailed access statistics. Especially interesting is the cache hit rate.

Varnishstat.png

Reload the Varnish configuration

To reload the Varnish configuration Debian includes a script.

/ Usr / share / varnish / reload vcl

0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: