Varnish Purge Not Working When Cleaning Magento Cache

cdnmagento2varnish

We have successfully configured varnish in our magento website, it's working great. But the problem is varnish is not purging when we clear the cache either via admin panel or ssh command. We restart varnish server every time. We have also configured CDN (It may be reason for this cache issue).
We have tried to set http_cache_hosts using the command

bin/magento setup:config:set --http-cache-hosts=xx.xx.xxx.xxx:6081

Also tried with ports 8080,6082

In our .vcl file

acl purge {
    "xx.xx.xxx.xxx";
}

Above configurations is not at all working. We are missing something to make it work. Can anyone help on this?

Best Answer

1- check varnish port using :

sudo netstat -ltnp 

in my case it's port 80 enter image description here

2-Update cache host using

php bin/magento setup:config:set --http-cache-hosts=xx.xx.xxx.xxx:80

here i'm using port 80 ( varnish cache port )

3- check your vcl settings ( i'm using ubuntu under: /etc/varnish/default.vcl )

backend default {
    .host = "XX.XX.XX.XX";//here replace localhost with your ip
    ....

acl purge {
    "XX.XX.XX.XX";//here replace localhost with your ip
   }

4-Now check if purge request received using

varnishlog -g request -q 'ReqMethod eq "PURGE"'

to send PURGE request go to the Admin, click SYSTEM > Tools > Cache Management, then click Flush Magento Cache at the top of the page.

or

using cmd

php bin/magento cache:flush 

Dont' forget to restart varnish after changes :

service varnish restart
Related Topic