We have a magento 2.4 installation and we are intrested in installing varnish cache for our website
We are using Plesk (Plesk Obsidian 18.0.37), so we found usefull to follow this guide:
But with magento's varnish v6 export .vcl configuration instead, with these statements different
Our varnish version chosen is 6.4.0-1
...
backend default {
.host = <plesk's and site's ip>
.port = "7080";
...
}
acl purge {
"localhost";
"<plesks's and site's ip>;
}
...
The installation looks successful but we are getting this error every time we try to connect with our demo subdomain
Error 503 Backend fetch failed
We tried replacing the backend default's ip with localhost and all sorts of different configurations within plesk panel but nothing seem to change anything
digging into the varnish's log using varnishlog -g raw -i backend_health
this error keeps popping out:
0 Backend_health - default Still sick -------- 0 5 10 0.000000 0.000000 "Open error 110 (Connection timed out)"
... using localhost as .host
this error keeps popping out:
0 Backend_health - default Still sick -------- 4 5 10 0.000000 0.000000 "Open error 101 (Network is unreachable)"
.. and finally using 127.0.0.1 as .host
instead of localhost:
acl purge {
"localhost";
"127.0.0.1";
"<plesks's and site's ip>;
}
and got this instead:
0 Backend_health - default Still sick -------- 4 5 10 0.000000 0.000000 "Open error 111 (Connection refused)"
which doesnt makes so much sense
we guessed it might be a firewall issue so we temporarily tried adding a rule within plesk's firewall saying: Allow incoming from <plesk's ip and site's ip>, 127.0.0.1 on all ports
but nothing changed with all three configurations
So does it have to do with firewall issues? or bad configuration?
Thanks alot in advance!
The issue was clearly the firewall!
Using localhost
or 127.0.0.1
for varnish configuration wasnt making much sense, because from the docker container's virtual enviroment perspective, there was no apache server installed that listens to port 7080, but instead there was at the host machine.
So there was no way docker could reach host's apache using localhost.
Whitelisting the source that docker's varnish come from, (docker's network interface) from firewall fixed the issue.
After whitelisting the docker's network ip address (including the bitmask notation (<docker's network ip>/16) for port 7080 that apache listens)) from plesk's firewall extension everything worked fine!
The website is way faster now with varnish, hope this gives you a hint if you encounter the same issue with docker and varnish at plesk.