Varnish

From Gentoo Wiki
Jump to: navigation, search
Resources

Varnish is a webcache and HTTP accelerator. It can either serve cached content, or retrieve content from a server and cache it. This helps to reduce I/O pressure for web servers that are serving many clients or have many requests.

Installation

USE flags

USE flags for www-servers/varnish Varnish is a state-of-the-art, high-performance HTTP accelerator

jemalloc Use dev-libs/jemalloc for memory management
jit Enable just-in-time compilation for improved performance. May prevent use of some PaX memory protection features in Gentoo Hardened.
static-libs Build static versions of dynamic libraries as well

Emerge

Install www-servers/varnish

root #emerge --ask www-servers/varnish

Configuration

Files

Global

Configuration is controlled by the /etc/varnish/default.vcl file.

FILE /etc/varnish/example.vcl
#
# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples.

# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;

# Default backend definition. Set this to point to your content server.
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

Any traffic pointed at port 8080 will travel through varnish.

Service

OpenRC

To start varnish immediately:

root #rc-service varnishd start

To start varnish at boot:

root #rc-update add varnishd default

systemd

To start varnish on boot:

root #systemctl enable varnishd

To start varnish immediately:

root #systemctl start varnishd

Troubleshooting

Verification

The curl command (net-misc/curl) can be used to verify that HTTP traffic is successfully traveling through the varnish proxy:

user $curl -I https://wiki.gentoo.org/wiki