1

I have configured the host and port to purge Varnish as it says in the official documentation:

bin/magento setup:config:set --http-cache-hosts=varnish_host:varnish_port

But when I try to save the modifications of a product for example, I get the following error in logs:

[2023-10-24 20:51:41] main.CRITICAL: No cache server(s) could be purged Cache host: host:port resulted in error message: Unable to connect to host:port . Error #0: stream_socket_client(): unable to connect to host:port (Connection timed out) {"method":"POST","url":"https://hostname/admin/catalog/product/save/id/1713369/type/simple/store/0/set/4/key/490cf9b0cfd68f1d33dda65d46d64d1f5e2cc41f6cf406c88c3bc12f91e1e41d/back/edit","invalidateInfo":{"server":"[object] (Laminas\Uri\Uri: http://host:port/)","formattedTagsChunk":"((^|,)cat_p_1713369(,|$))"}} []

Important: Varnish is configured on another server, should I add some additional permission so that the purge is sent from the server where my application is to the server where Varnish is?

Edit:

Purge part in vcl file:

if (req.method == "PURGE") {
        if (client.ip !~ purge) {
            return (synth(405, "Method not allowed"));
        }
        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"));
}

1 Answer 1

1

I'd like to refer to https://www.varnish-software.com/developers/tutorials/configuring-varnish-magento/ as an additional source of information. It contains more Varnish-specific information.

In terms of debugging, please go through the following checklist:

  • Check on which port number Varnish is configured. sudo systemctl cat varnish can help you visualize the right -a parameters for the varnishd program
  • Try to access Varnish on that port through a basic curl command on your Magento server. See if it responds
  • Ensure that the IP address of your Magento server is listed in the VCL file's Access Control List
  • Try a curl -XPURGE -H"X-Magento-Tags-Pattern: test" http://varnish_host:varnish_port on your Magento server and check what the status code/message is
  • If the curl command returns a 405 Method not allowed, your ACL is still not correctly configured

Depending on the outcome of these steps, additional debugging can still be done. The primary objective is the ensure the Varnish endpoint is reachable over HTTP from your Magento server without the ACL interfering.

5
  • Thank you for your answer, I carried out several tests and the problem was in the communication between the 2 servers (back server and varnish server), with the command you have sent I was able to do direct Purge tests directly obtaining "200, "Purged"". Commented Nov 8, 2023 at 16:05
  • But I have a big doubt, is it possible that the purge to varnish from the cache:clean of the application is done only to the product that I modified? When I execute the cache:clean command after modifying the product, everything is purged the Varnish cache, is there a way to send the purge only to the modification I made? I add part of the vcl file in the edit. Commented Nov 8, 2023 at 16:06
  • @DiegoCastro cache:clean indeed purges the entire cache. What you could do is check the X-Magento-Tags response header of the page you want to purge. And include that is the tag in the curl command I posted above. This is of course only for debugging. If you update the product in the Magento CMS, the right purge call should be executed anyway. Commented Nov 9, 2023 at 15:34
  • Thank you, this works! Commented Nov 9, 2023 at 22:37
  • Could you please help me with this question if you know it? Thank you Commented Nov 23, 2023 at 2:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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