I enabled varnish cache from admin(magento 2.4), then I ran this command

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

Now I can't run the upgrade script. I'm getting this error:

Error flushing Varnish server. Host: "". PURGE response code: 405 message: Not Allowed
Server: nginx/1.18.0 (Ubuntu)

I have not changed anything in /etc/varnish/default.vcl and in /etc/default/varnish

Any kind of help would be appreciated

1 Answer 1


The problem is related to the purging ACL in your VCL file. Apparently the client IP doesn't match any IP address in the ACL.

This somewhat makes sense, because Varnish doesn't receive the actual client IP address, because Nginx is jammed in between as a TLS proxy.

Please share your full VCL file, including the purging ACL.

Potential solutions

  1. Modify the VCL to use the value of the X-Forwarded-For header instead of client.ip
  2. Add the port of Varnish server to the IP address of your --http-cache-hosts parameter.

The 2nd solution is probably the easiest one because it doesn't require a lot of effort. If Varnish runs on port 6081 for example, your config command could look like this:

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

This will ensure that Varnish receives the purges directly, rather than through ports 80 or 8080 that are configured by Nginx.

See https://devdocs.magento.com/guides/v2.4/config-guide/varnish/use-varnish-cache.html for more information.

  • This is my default vcl - i.imgur.com/vO9Ikmo.png
    – Hgresa
    Jul 28, 2021 at 6:18
  • @Hgresa That VCL file you shared is indeed a default VCL file, but it's not your VCL file because it's practically empty. I'm interested in your VCL file, and specifically the ACL & PURGE logic. Please also share your systemd configuration, because I want to know on which host & port your Varnish is listening. This is relevant for the bin/magento setup:config:set --http-cache-hosts command. Jul 28, 2021 at 6:42

Your Answer

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

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