1

I have a Magento store configured with Varnish. When everything is up to date site is fast. If I change something in the backend it doesn't get reflected on frontend unless I manually delete var/cache/mage--* folders.

By the looks of the documentation, this folder should be empty after I configured Varnish.

How do I debug this?

9
  • Can you confirm you have followed all the steps mentioned here devdocs.magento.com/guides/v2.4/config-guide/varnish/…
    – Sarvagya
    Feb 9 at 15:57
  • Yes, I can confirm I followed all those steps, plus more from other guides.
    – Odin
    Feb 9 at 16:07
  • in your varnish vcl comment out the unset resp.http.X-Varnish command and then restart varnish - if varnish is working you will see an x-varnish and x-magento-cache header being sent when you load a page. x-magento-cache will show HIT or MISS depending on if the page is cached or not. If you don't see this header varnish is not configured correctly.
    – paj
    Feb 9 at 17:39
  • @paj did what you told, there's no x-magento-cache, but there is x-varnish. Maybe because this ecommerce is behind cloudflare?
    – Odin
    Feb 9 at 18:54
  • Well the varnish header shows that you are talking to the varnish server, if you are in production mode the other headers might not be shown - I am not sure about that - if you still have files being produced in var/cache then your magento varnish configuration is incorrect.
    – paj
    Feb 9 at 19:03
0

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 magento2_php-apache_1 is the hostname of your Magento 2 server and backend_port is the tcp port of the content (magento 2) server

system/full_page_cache/caching_application - 2
system/full_page_cache/varnish/access_list - magento2_php-apache_1
system/full_page_cache/varnish/backend_host - magento2_php-apache_1
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.
3
  • Since my varnish and my magento are on the same server, localhost and/or 127.0.0.1 should be correct, right? Also, varnish is running on port 6082, so it should be that port, correct?
    – Odin
    Feb 9 at 19:38
  • 6082 is the varnish admin port. The port you configure in Magento is your Magento servers http port, if varnish is using TCP80 then it will be something else i.e. 8080 - 6082 is not correct.
    – paj
    Feb 9 at 20:16
  • Stupid mistake! I'll edit accordingly and provide feedback. Thanks @paj !
    – Odin
    Feb 10 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.