special sponsors

# Varnish

Varnish Cache (opens new window) 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 options, in addition to the build steps and overrides that are available to every service, are shown below:

    type: varnish:4.1
      - appserver
    backend_port: 80
    ssl: false
      vcl: SEE BELOW
      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.

An example of a Landofile's services config that connects to a nginx backend called web1 is shown below:

    type: varnish
      - 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.

    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 (opens new window), 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 (opens new window) file to mimic the setup that you need to test against. You can do that by setting config.vcl as shown below:

A hypothetical project

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

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

Landofile's varnish config

    type: varnish
      vcl: config/custom.vcl

# Advanced

There are also several various envvars (opens new window) 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 as shown below:

  type: varnish
    - database

# 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.