You can check your Varnish configuration with n98-magerun2
Use the command
n98-magerun2.phar config:show | grep full_page_cache
You should see something like the following where varnish is the hostname of your varnish server and backend_port is the tcp port of the content (magento) server
system/full_page_cache/caching_application - 2
system/full_page_cache/varnish/access_list - varnish
system/full_page_cache/varnish/backend_host - varnish
system/full_page_cache/varnish/backend_port - 8080
system/full_page_cache/varnish/grace_period - 300
You should also confirm your env.php
is configured with an http_cache_host
'http_cache_hosts' => [
[
'host' => 'varnish',
'port' => '6081'
]
],
The port here is the port Magento uses to communicate with the varnish server. You can also set this configuration with
magento setup:config:set --http-cache-hosts=127.0.0.1:6081
The varnish vcl should also be configured correctly with the port of your content (magento) server
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8080";
}
Don’t get the ports mixed up :
- By default Varnish is configured to listen for incoming external client http requests on TCP 6081.
- The backend_port configured in admin is only used for the vcl config generation.
- The env.php http_cache_hosts port is the port used to communicate with varnish.