I've setup Varnish Cache for my Magento 2 site but the System->Cache Management never clears it.
I also don't see in the configuration somewhere to specify the varnish secret, if required.
We use M2.1 and have no problem so far using varnish with nginx and php7.
I think you do not see the varnish in the cache backend but it behaves like the normal magento cache if varnish is installed correctly meaning varnish gets cleared for pages when for example saving them or stock changes. hope this helps
@andidhouse do you have a secret specified:
/usr/sbin/varnishd -j unix,user=vcache -a 0.0.0.0:80 -T 0.0.0.0:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m -t 120 -p vcc_allow_inline_c=on -p feature=+esi_disable_xml_check,+esi_ignore_other_elements -p cli_buffer=35000 -p thread_pools=2 -p syslog_cli_traffic=off
@craigcarnell - i am not shure. What is this for? i can ask our technical stuff if this is important.
@andidhouse Are you referring to the secret key? It's an extra bit of security
I have used the following command to monitor in real time if Varnish receives the purge request or not:
varnishlog -g request -q 'ReqMethod eq "PURGE"'
Maybe this can help debug.
@pantaoran This is the output of selecting refresh page cache on my server:
* << Request >> 295114
- Begin req 295113 rxreq
- Timestamp Start: 1484221159.429986 0.000000 0.000000
- Timestamp Req: 1484221159.429986 0.000000 0.000000
- ReqStart 10.182.70.125 45096
- ReqMethod PURGE
- ReqURL /
- ReqProtocol HTTP/1.1
- ReqHeader X-Magento-Tags-Pattern: .*
- ReqHeader X-Forwarded-For: 10.182.70.125
- VCL_call RECV
- VCL_acl NO_MATCH purge
- VCL_return synth
- VCL_call HASH
- VCL_return lookup
- Timestamp Process: 1484221159.430034 0.000048 0.000048
- RespHeader Date: Thu, 12 Jan 2017 11:39:19 GMT
- RespHeader Server: Varnish
- RespHeader X-Varnish: 295114
- RespProtocol HTTP/1.1
- RespStatus 405
- RespReason Method Not Allowed
- RespReason Method not allowed
- VCL_call SYNTH
- RespHeader Content-Type: text/html; charset=utf-8
- RespHeader Retry-After: 5
- VCL_return deliver
- RespHeader Content-Length: 277
- Storage malloc Transient
- Debug "RES_MODE 2"
- RespHeader Connection: keep-alive
- Timestamp Resp: 1484221159.430138 0.000152 0.000104
- ReqAcct 48 0 48 209 277 486
- End
So your Varnish received the purge request but didn't act on it due to "Method Not Allowed".
Did you whitelist your php host in the varnish.vcl?
@pantaoran
My VCL:
backend default {
.host = "localhost";
.port = "8080";
}
acl purge {
"localhost";
}
I tried changing it to 127.0.0.1 but that made no difference.
Magento appears to be sending the private IP of the machine, instead of 127.0.0.1/localhost when I try to clear the cache in the admin, which is why it doesn't match.
The private IP starts with 10.xx
I can see the IP in your output above. So are Magento(PHP) and Varnish on the same host/IP or not?
If not, can you reference it with a hostname instead of an IP?
@pantaoran they are on the same host. Unfortunately our VCLs are controlled by Varnish, so it's not possible to have different configurations. But I will put a fix in place for the purge to cater for this
For me it isn't working. Have Magento 2.2 and i can't see a purge request.
magento setup:config:set --http-cache-hosts=127.0.0.1
and tried to look for a request with: varnishlog -g request -q 'ReqMethod eq "PURGE"'
somebody has news about varnish purge from magento?
thanks
I am also not able to purge varnish cache using Default Magento php bin/magento cache:flush command, please guide me on this
Most helpful comment
I have used the following command to monitor in real time if Varnish receives the purge request or not:
varnishlog -g request -q 'ReqMethod eq "PURGE"'Maybe this can help debug.