Вопрос

I am trying from console to purge and refresh one specific link of my magento 2 store in Varnish. I don't want to clear the whole cache but just one link.

I tried:

curl -X PURGE http://www.example.com/my/link

or

curl -X PURGE https://www.example.com/my/link

but don't work.

Result of curl is:

<!DOCTYPE html>
<html>
  <head>
    <title>400 X-Magento-Tags-Pattern or X-Pool header required</title>
  </head>
  <body>
    <h1>Error 400 X-Magento-Tags-Pattern or X-Pool header required</h1>
    <p>X-Magento-Tags-Pattern or X-Pool header required</p>
    <h3>Guru Meditation:</h3>
    <p>XID: 3000241</p>
    <hr>
    <p>Varnish cache server</p>
  </body>
</html>

Then I tried with varnishadm

varnishadm -T 127.0.0.1:6082 -S /etc/varnish/secret ban "req.http.host == example.com && req.url == /my/link"

This seems working but I am not sure. I used "ban" there and I don't know if with this I excluded this link from Varnish?

I use Magento 2 default.vcl, Varnish 6 and Nginx. I saw that Magento's vcl has this section for purging:

acl purge {
    "localhost";
}
sub vcl_recv {
    if (req.method == "PURGE") {
    # check if the client is allowed to purge content
        if (client.ip !~ purge) {
            return (synth(405, "Method not allowed"));
        }
        # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
        # has been added to the response in your backend server config. This is used, for example, by the
        # capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
        if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
            return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
        }
        if (req.http.X-Magento-Tags-Pattern) {
          ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
        }
        if (req.http.X-Pool) {
          ban("obj.http.X-Pool ~ " + req.http.X-Pool);
        }
        return (synth(200, "Purged"));
    }

As I understand this section with the appropriate insert in

env.php

it permits to clean Varnish from magento admin which for me it works.

But why with

curl -X purge

can't clear one link?

What I do wrong? Can somebody explain please all these?

Это было полезно?

Решение

The result of your curl command would help? If empty try adding -I.

Solution from the comments:

Add any or both of the mentioned headers in your curl.

curl -X PURGE -H 'X-Magento-Tags-Pattern: .*' https://www.example.com/my/link

You can find what magento sets by eg. varnishlog | grep -i tags

Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top