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.
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.
services: myservice: 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.
An example of a Landofile's
services config that connects to a
nginx backend called
web1 is shown below:
services: myservice: 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: myservice: type: varnish backend_port: 8080
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 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
services: myservice: type: varnish config: vcl: config/custom.vcl
There are also several 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 as shown below:
myservice: 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