I've installed 3rd party extension for AMP and it was working fine before installing varnish. After varnish, I am getting normal page and it starts fetching amp pages after opening 2-3 pages.
Has anyone any idea why this is happening?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI've installed 3rd party extension for AMP and it was working fine before installing varnish. After varnish, I am getting normal page and it starts fetching amp pages after opening 2-3 pages.
Has anyone any idea why this is happening?
Easy fix.
Configure your default.vcl thats located in /etc/varnish/ with the following:
# Bypass shopping cart, checkout and search requests
if (req.url ~ "/checkout" || req.url ~ "/catalogsearch" ) {
return (pass);
}
# Bypass shopping cart, checkout and search requests
if (req.url ~ "/checkout" || req.url ~ "/catalogsearch" || req.url ~ "/?amp=1") {
return (pass);
}
The vcl_recv sub
checks the request before asking the backend for cache.
Therefore checking for the ?amp=1
parameter and not caching the pages will fix your issue.
AMP pages are made to work fast and you don't really need cache for them.
Use https://github.com/varnishcache/varnish-devicedetect
All you have to do is download that devicedetect.vcl file to /etc/varnish and then use it as following in the default.vcl:
import std;
include "devicedetect.vcl";
# The minimal Varnish version is 5.0
# For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https'
backend default {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 600s;
}
acl purge {
"127.0.0.1";
}
sub vcl_recv {
call devicedetect;
if (req.http.X-UA-Device ~ "^mobile" || req.http.X-UA-device ~ "^tablet") {
return(pass);
}
}
the problem happened is ,by default nginx(server) uses port 80,so when you setup varnish then you change nginx port to another(say 8080) and port 80 is used by varnish.The error will appear when it comes to reboot your system or closing your current loaded tab in your browser.