Varnish Cache

The fastest and most advanced HTTP accelerator

Varnish Cache is an open source HTTP accelerator, also known as a reverse caching proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. Varnish is really, really fast. It typically speeds up delivery with a factor of 300 - 1000x, depending on your architecture.

Getting started with Varnish Read the docs

What is Varnish?

Varnish Cache is a downstream distribution of the Vinyl Cache open source project, delivering a stable supported LTS release with additional tooling and features on top.

The term Varnish represents the complete technology ecosystem that surrounds Varnish. This includes Varnish Cache, Varnish Enterprise, and other related tools and products that are offered by Varnish Software, and by the community at large.

How does Varnish work?

Varnish sits in front of your web server, proxies HTTP requests, and caches responses from your web server to improve performance and reduce the load on your backend servers. This is illustrated in the diagram below.

Varnish Cache Diagram
A diagram that illustrates how Varnish works.

Cached objects get served from Varnish until they expire. Varnish respects the conventional HTTP headers to control caching behavior and to set the expiration time of a cached object.

Thanks to the built-in Varnish Configuration Language (VCL), you can customize caching policies to suit your specific needs.

Key features

Varnish has a rich set of features and capabilities, which you can read about in the documentation.

  • Varnish is extremely fast and scalableExtremely fast and scalable
  • Varnish Cache is free and open source softwareVarnish Cache is free and open source software
  • Varnish follows HTTP caching conventionsFollows HTTP caching conventions
  • Varnish is highly customizeable thanks to VCLBuilt-in VCL programming language
  • Varnish provides extensive metrics and logs for complete observabilityExtensive metrics and logs for complete observability
  • SSL SupportDynamic Backend with SSL support
  • SSL SupportMore to come soon...

Getting started with Varnish

Varnish is available on various platforms, and can be installed using Docker or using packages for various DEB-based and RPM-based Linux distributions.

Pull in the Docker image:

docker pull varnish

Run the Docker container with the standard configuration:

docker run --rm -p 80:80 --name varnish varnish

Run the Docker container with a custom VCL file:

docker run --rm -p 80:80 --name varnish -v $(pwd)/default.vcl:/etc/varnish/default.vcl:ro varnish

Mounts default.vcl into the Docker container to customize the caching policies of Varnish. Makes a Varnish available on port 80 of your local machine.

Customize the VCL:

vcl 4.1; backend default { .host = "origin.example.com"; .port = "80"; }

This VCL change configures the backend server for Varnish to forward requests to origin.example.com on port 80. Use the -v $(pwd)/default.vcl:/etc/varnish/default.vcl:ro option in Docker to mount the default.vcl file and customize the caching policies of Varnish.

Learn more about deploying Varnish with Docker by reading the install guide.

Install guide

Install the Helm chart:

helm install varnish -f values.yaml oci://docker.io/varnish/varnish-cache

Customize the values.yaml file to configure the Varnish Helm chart.

Run kubectl get svc varnish-varnish-cache to get the cluster IP address and node port of the Varnish Cache service. Other service types and Ingress are also supported.

Learn more about deploying Varnish on Kubernetes by reading the install guide.

Install guide

Update the package list:

sudo apt-get update

Configure the package registry to install Orca on Debian and Ubuntu Linux servers:

curl -Ls https://packages.varnish-software.com/varnish/bootstrap-deb.sh | sh

Install Varnish:

sudo apt-get install -y varnish

Edit the varnish systemd service:

sudo systemctl edit --full varnish

Change the port number and cache size in the varnish.service systemd parameters:

ExecStart=/usr/sbin/varnishd \ -a :80 \ -a localhost:8443,PROXY \ -f /etc/varnish/default.vcl \ -P %t/%N/varnishd.pid \ -p feature=+http2 \ -s malloc,2g

This systemd configuration change sets the Varnish service to listen on port 80, and allocates 2GB of memory for caching.

Open the VCL file:

sudo vim /etc/varnish/default.vcl

Customize the VCL:

vcl 4.1; backend default { .host = "origin.example.com"; .port = "80"; }

This VCL change configures the backend server for Varnish to forward requests to origin.example.com on port 80.

Restart Varnish to activate the changes:

sudo systemctl restart varnish

Learn more about installing Varnish on Debian or Ubuntu by reading the install guide.

Install guide

Configure the package registry to install Orca on Debian and Ubuntu Linux servers:

curl -s https://packages.varnish-software.com/varnish/bootstrap-rpm.sh | sh

Install Varnish:

sudo yum install -y varnish

Edit the varnish systemd service:

sudo systemctl edit --full varnish

Change the port number and cache size in the varnish.service systemd parameters:

ExecStart=/usr/sbin/varnishd \ -a :80 \ -a localhost:8443,PROXY \ -f /etc/varnish/default.vcl \ -P %t/%N/varnishd.pid \ -p feature=+http2 \ -s malloc,2g

This systemd configuration change sets the Varnish service to listen on port 80, and allocates 2GB of memory for caching.

Open the VCL file:

sudo vim /etc/varnish/default.vcl

Customize the VCL:

vcl 4.1; backend default { .host = "origin.example.com"; .port = "80"; }

This VCL change configures the backend server for Varnish to forward requests to origin.example.com on port 80.

Restart Varnish to activate the changes:

sudo systemctl restart varnish

Learn more about installing Varnish on Red Hat Linux and other compatible distributions by reading the install guide.

Install guide

Getting help

If you need help with Varnish and the docs give you no clue on what to do there are several options available to you.

Discord Channel

While newer and less populated than the IRC channel, the Varnish discord server is also a good place to ask questions about configuration, HTTP, vmods or anything that’s even remotely related to Varnish.

StackOverflow

You can ask questions and find answers about Varnish and VCL on StackOverflow using the varnish or the varnish-vcl tag.

Social Media

There is a Varnish Cache group on LinkedIn where you can ask and answer questions.

We are also available on X as @varnishcache

Commercial support

If you need more hands-on assistance, or specialized advice, commercial support options are available through Varnish Software, the company behind Varnish.

Get in touch with Varnish Software.