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: 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
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
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
./ |-- config |-- custom.vcl |-- .lando.yml
Landofile's varnish config
services: my-service: type: varnish config: vcl: config/custom.vcl
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