Description
This component is responsible for setting up Varnish for your instance.
Varnish is a cache that sits in front of Magento to serve web pages faster, it is highly recommend that it be enabled. For more information see Magento dev docs
Settings
When varnish is first enabled the default values will be appropriate for most setups.
- Enable - If varnish is enabled or not
- Version - The version of varnish to use
- Enable Probe - Whether or not to enable varnish probing
- Additional Purge IPs - IPs (in addition to Magentos) that should be allowed to
PURGE
varnish cache. - Additional Service Arguments - These are arguments passed to the varnish service when it starts. (see varnish params)
- Additional Environment Params - These are additional variables that can be used in your vcl file.
In Source Code Configuration
We understand that some people have some custom requirements when it comes to Varnish.
To support this MDOQ will always try and read a varnish.vcl from mdoq/varnish/varnish.vcl
, if this is not found MDOQ will fall back to it's default vcl.
This default vcl will be placed into mdoq/varnish/varnish.vcl
. (So if it's not there you don't need to worry MDOQ will add it for you.) If you make changes to this file you will need to recreate the varnish component.
We would recommend adding this file to source control so that changes can be tracked and version controlled.
Because this file contains infrastructure configuration such as backend host and backend port, MDOQ utilizes the dockerize utility, this allows configuration to be templated using golang templtate. The variables available to you in the template are:
Variable | Description | Example | Requirement |
---|---|---|---|
BACKEND_HOST | The backend host varnish will make requests to. | .host = "{{ .Env.BACKEND_HOST }}"; |
Mandatory |
BACKEND_PORT | The port of the backend host varnish will make requests to. | .port = "{{ .Env.BACKEND_PORT }}"; |
Mandatory |
PURGE_IPS | Additional IPs that can PURGE varnish cache controller by purge IPs setting. |
see purge IPs example | Mandatory |
PROBE_ENABLED | If varnish's probe is enabled this is controlled by the enable probe setting. | see probe enabled example | Optional |
N.B If any mandatory variables are missing from the template your instance will not work.
In addition to the mandatory variables your vcl file must contain:
- Addition vcl list called
health_check
(this can straight under the purge one)
for example
- The following logic at the top of the
vcl_recv
subroutine
These additions allow MDOQ to check the health of Varnish. Without them MDOQ may determine the service to be down.
Purge IPs Example
Probe Enabled Example
Debugging
To aid in debugging when MDOQ creates the varnish component it will also write the processed vcl template (mdoq/varnish/varnish.vcl
) to mdoq/varnish/varnish.out.vcl
. This isn't the file that varnish is using but the content will be the same as the file varnish is using.
Something is wrong
If you feel that you are not getting optimal Varnish performance it might be that there is code invalidating the cacheable state of the page(s). Here is a method to investigate why a page might be bypassing varnish cache.
Open the file vendor/magento/framework/View/Layout.php
and insert the code
When reloading the page you should then see information on the XML block responsible.