From Gentoo Wiki
Jump to:navigation Jump to:search

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.


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
unwind Add support for call stack unwinding and function name resolution


Install www-servers/varnish

root #emerge --ask www-servers/varnish




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
# and 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 = "";
    .port = "8080";

Any traffic pointed at port 8080 will travel through varnish.



To start varnish immediately:

root #rc-service varnishd start

To start varnish at boot:

root #rc-update add varnishd default


To start varnish on boot:

root #systemctl enable varnishd

To start varnish immediately:

root #systemctl start varnishd



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

user $curl -I