Varnish

Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents.

You can easily add it to your Lando app by adding an entry to the services top-level config in your Landofile.

Supported versions

Patch versions

This service does not support patch versions but if you really need something like that you could consider using either a custom compose service or a service overrides.

Configuration

Here are the configuration options, set to the default values, for this service. If you are unsure about where this goes or what this means we highly recommend scanning the services documentation to get a good handle on how the magicks work.

Also note that the below options are in addition to the build steps and overrides that are available to every service.

services:
  my-service:
    type: varnish:4.1
    backends:
      - appserver
    backend_port: 80
    ssl: false
    config:
      vcl: SEE BELOW
    overrides:
      environment: SEE BELOW

Connecting to backend services

You will need to list the http backend services you want varnish to use. Note that the services in this list should be serving content on port 80. They can be discovered by running lando info.

Here is an example of a Landofile's services config that connects to a nginx backend called web1.

services:
  my-service:
    type: varnish
    backends:
      - web1
  web1:
    type: nginx

Setting a port

While we assume your varnish service is running on port 80 we recognize that many apps also run on other ports. You can easily change our default to match whatever your app needs. Note that this port applies to ALL BACKENDS.

services:
  my-service:
    type: varnish
    backend_port: 8080

Using SSL

In order to access varnish over https you only need to set ssl: true. However, because varnish is not built to run over https we will spin up an additional nginx container called SERVICE_ssl and handle SSL termination there.

Using a custom VCL file

It's highly likely you will want to use your own vcl file to mimic the setup that you need to test against. You can do that by setting config.vcl as in below:

A hypothetical project

Note that you can put your configuration files anywhere inside your application directory. We use a config directory in the below example but you can call it whatever you want such as .lando.

./
|-- config
   |-- custom.vcl
|-- .lando.yml

Landofile's varnish config

services:
  my-service:
    type: varnish
    config:
      vcl: config/custom.vcl

Advanced

There are also serveral various envvars exposed by the underlying image we use that you can set to further customize how your Varnish works. These are not officially supported so we highly recommend you do not alter them unless you know what you are doing. Even then YMMV.

That said, you will need to use a service override to take advantage of them like so:

my-service:
  type: varnish
  hosts:
    - database
  overrides:
    environment:
      BACKENDS_PROBE_ENABLED: false
      DNS_ENABLED: true
      BACKENDS_PROBE_INTERVAL: 3s
      BACKENDS_PROBE_TIMEOUT: 1s
      BACKENDS_PROBE_WINDOW: 3
      BACKENDS_PROBE_THRESHOLD: 2

Getting information

You can get connection and credential information about your varnish instance by running lando info. It may also be worth checking out our accessing services externally guide.