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
Varnish Versions
Version | Status |
7.6 | Active |
7.5 | Active |
7.4 | Deprecated |
7.3 | Deprecated |
7.2 | Deprecated |
7.1 | Deprecated |
7.0 | Deprecated |
6.6 | Deprecated |
6.5 | Deprecated |
6.4 | Deprecated |
6.3 | Deprecated |
6.2 | Deprecated |
6.1 | Deprecated |
6.0 | Active |
5.2 | Deprecated |
5.1 | Deprecated |
5.0 | Deprecated |
4.1 | Deprecated |
4.0 | Deprecated |
3.0 | Deprecated |
2.1 | Deprecated |
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.
Varnish Cache Not Clearing
From time to time you may update a product or page and find that the change doesn't show on the frontend for around 24 hours, this is a sign that varnish isn't being purged propperly. The following are a set of steps to determine if the likely cause of this is infrastructure or application.
- Check env configuration.
Download the latest code backup
Extract the backup on your machine
Then open the file app/etc/env.php
In this file there should be a line like
'http_cache_hosts' => [
Where XXXX is the ID of your instance
[
'host' => 'XXXX-varnish' ] ],
If this isn't the case please reach out to our support - Check the Magento configuration
Stores > Configuration > Advanced | System > Full Page Cache
Caching Application should be set to Varnish
You should be fine to simply change and save this. - Check that cache is enabled
System > Cache Management
Page Cache should be enabled
If not you will need to enable - Check saving a CMS page.
Simply add some none whitespace to a CMS page (such as a ".") then save the page. When reloading the page on the frontend it should show. - Check saving a product
Simply add some none whitespace to the products description (such as a ".") then save the product. When reloading the page on the frontend it should show. - Check saving a category
Simply add some none whitespace to the categories description (such as a ".") then save the category. When reloading the page on the frontend it should show.
If any of 4,5,6 works, this suggest an application issue, if non of them work it suggests the error is infrastructer based, please reach out to our support.