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?

  • I think your problem is happening because of varnish store cache for some amp pages as a normal page, it happened because the first visiting your page was no amp page. But this is just a guess. Can you explain in details your problem, better give me a URL to your site where I can reproduce the problem. Apr 20, 2019 at 18:14
  • After opening 2-3 pages, it will have ?amp=1 at the end of URL and it means it's an AMP @PetroChaikivskyi Apr 22, 2019 at 5:00
  • As I can see, you have amp home page, category page, and cms pages. On every page, I saw no less than tree validation errors. I can't explain your problem as can't see implementation your amp extension and varnish configuration, sorry Apr 22, 2019 at 19:15

2 Answers 2


Easy fix.

Configure your default.vcl thats located in /etc/varnish/ with the following:

  1. Find
# Bypass shopping cart, checkout and search requests
    if (req.url ~ "/checkout" || req.url ~ "/catalogsearch" ) {
        return (pass);
  1. Change it with the following:
  # 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 = "";
    .port = "8080";
    .first_byte_timeout = 600s;


acl purge {

sub vcl_recv {
  call devicedetect;
    if (req.http.X-UA-Device ~ "^mobile" || req.http.X-UA-device ~ "^tablet") {

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.

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.