Troubleshooting: Varnish 503 errors
Troubleshooting: Varnish 503 errors
This guide will: Help you to identify what is causing the 503 Varnish error, and execute a solution.
Contents:
- Overview
- Fix 1: Incorrect path to health-check.php
- Fix 2: Redis is being used for full page caching
- Fix 3: Length of cache tags used by Magento exceed Varnish’s default value
- Video tutorial
Overview:
If you have Varnish enabled on your Magento 2 site and you are seeing a 503 error, you may need to make some adjustments to your site and the server’s Varnish configuration in order to get it working.
This guide will help to troubleshoot some of the most common reasons for 503 errors when using Varnish.
Fix 1: 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’.
- Restart Varnish.
Fix 2: Redis is being used for full page caching
You can use both Varnish and Redis together, however you cannot use both to complete full page caching. To find out if Redis is the cause of the 503 error, you need to disable Redis in your site’s env.php.
- Locate:
/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.
Note: A good reference guide for setting-up Magento 2 with Varnish and Redis working together can be found here. However, skip the parts around Varnish specifically, as these will have been already completed if your Varnish toggle is enabled in the platform.
Fix 3: Length of cache tags used by Magento exceed Varnish’s default value
This can happen with sites that have a lot of products, and will typically manifest itself on product category pages, or pages which 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 than the default value (http_resp_hdr_len) set in Varnish.
- To fix, open up the following file:
nano /etc/default/varnish
- Amend, or add, the following values:
-p http_resp_hdr_len=70000 \
-p http_resp_size=100000 \
- Restart Varnish.
Video tutorial:
Still having issues?
Further reading:
- KB ARTICLE or
- BLOG LINK
Updated about 1 month ago