If you have enabled Varnish on your Magento 2 site and you are seeing a 503 error being displayed then you may need to make some adjustments to your site and the servers Varnish configuration in order to get it working. 


There are many reasons a Magento site will show a 503 error after Varnish has been enabled in STORM. A lot of these will be down to how the site is built and configured. It's particularly an issue when enabling Varnish on an existing site due to the amount of variables in play. However if you are starting a new Magento 2 project using STORM and Varnish then Varnish should work out of the box.


This guide offers some tips to help troubleshoot some of the most common reasons for 503 errors when using Varnish on STORM.


Incorrect path to health-check.php


The Varnish configuration file that Magento exports specifies a path to a php file within the site called health_check.php. If the path on the site is different to what is set in the Varnish configuration file it can cause a 503 error when you enable Varnish. 


To fix update the following file:


/etc/varnish/default.vcl

Comment out:


backend default {
    .host = "127.0.0.1";
    .port = "8080";
    .first_byte_timeout = 600s;
    .probe = {
       .url = "/public/pub/health_check.php";
        .timeout = 2s;
        .interval = 5s;
        .window = 10;
        .threshold = 5;
   }
}

And replace with:


# Default backend definition. Set this to point to your content server.
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}


This removes the check for health_check.php. Once your changes have been made, restart Varnish. 

Redis being used for full page caching


You can use both Varnish and Redis together however you can't use both for full page caching. To find out if Redis is the cause of the 503 error then disable Redis in your sites env.php.


This should be located in:

/home/storm/sites/sitename-com/public/app/etc/env.php

Open the file and comment out the Redis lines, then see if the site loads.


A good reference guide for setting up Magento 2 with Varnish and Redis working together nicely can be found below (Skipping the Varnish bits as this is already done if the Varnish toggle is enabled in STORM):


https://cloudkul.com/blog/configure-varnish-and-redis-magento-2/

Length of cache tags used by Magento exceed Varnish’s default value


This can happen with sites that have a lot of products and typically manifests itself on product category pages or pages that display a lot of products all on one page. Each product adds a header tag to the request and when you reach a certain number of products it can end up being higher that the default http_resp_hdr_len value set in Varnish.


To fix this, open up the following file:

nano /etc/default/varnish

And amend the following values (or add them if they are missing):

-p http_resp_hdr_len=70000 \

-p http_resp_size=100000 \
Then restart Varnish.