Getting 503 Fetch Failed in M2. I've redis and Varnish server running along with Nginx my varnishlog says
my default.vcl
 vcl 4.0;
import std;
# The minimal Varnish version is 4.0
# For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https'
backend default {
 .host = "localhost";
 .port = "8080";
}
acl purge {
 "localhost";
}
sub vcl_recv {
 if (req.method == "PURGE") {
 if (client.ip !~ purge) {
 return (synth(405, "Method not allowed"));
 }
 if (!req.http.X-Magento-Tags-Pattern) {
 return (synth(400, "X-Magento-Tags-Pattern header required"));
 }
 ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
 return (synth(200, "Purged"));
 }
VARNISH LOG
 * << Request >> 32838
- Begin req 32837 rxreq
- Timestamp Start: 1468597956.246653 0.000000 0.000000
- Timestamp Req: 1468597956.246653 0.000000 0.000000
- ReqStart 192.168.1.1 19182
- ReqMethod GET
- ReqURL /robots.txt
- ReqProtocol HTTP/1.1
- ReqHeader Cache-Control: no-cache
- ReqHeader Connection: Keep-Alive
- ReqHeader Pragma: no-cache
- ReqHeader Accept: */*
- ReqHeader Accept-Encoding:
- ReqHeader From: bingbot(at)microsoft.com
- ReqHeader Host: www.salon-towels.com
- ReqHeader User-Agent: Mozilla/5.0 (compatible; bingbot/2.0; +http://www
- ReqHeader X-Forwarded-For: 192.168.1.1
- VCL_call RECV
- ReqURL /robots.txt
- VCL_return hash
- ReqUnset Accept-Encoding:
- VCL_call HASH
- VCL_return lookup
- VCL_call MISS
- VCL_return fetch
- Link bereq 32839 fetch
- Timestamp Fetch: 1468597961.245436 4.998783 4.998783
- RespProtocol HTTP/1.1
- RespStatus 503
- RespReason Backend fetch failed
- RespHeader Date: 2016年7月15日 15:52:41 GMT
- RespHeader Server: Varnish
- RespHeader Content-Type: text/html; charset=utf-8
- RespHeader Retry-After: 5
- RespHeader X-Varnish: 32838
- RespHeader Age: 0
- RespHeader Via: 1.1 varnish-v4
- VCL_call DELIVER
- RespUnset Age: 0
- RespUnset Server: Varnish
- RespUnset X-Varnish: 32838
- RespUnset Via: 1.1 varnish-v4
- VCL_return deliver
- Timestamp Process: 1468597961.245516 4.998863 0.000080
- RespHeader Content-Length: 282
- Debug "RES_MODE 2"
- RespHeader Connection: keep-alive
- Timestamp Resp: 1468597961.245621 4.998968 0.000105
- ReqAcct 272 0 272 175 282 457
- End
* << Session >> 32837
- Begin sess 0 HTTP/1
- SessOpen 192.168.1.1 19182 :80 192.168.1.34 80 1468597956.246550 15
- Link req 32838 rxreq
- SessClose REM_CLOSE 5.082
6 Answers 6
In Magento 2, this error is caused because the length of cache tags is more than 8192 characters. You can fix this error by increasing http_resp_hdr_len value in varnish configuration file.
I followed this tutorial https://magentip.com/magento-2-error-503-backend-fetch-failed-with-varnish-cache/ and successfully fixed that error.
Step 1: Depend on your OS, navigate to:
Ubuntu: /etc/default/varnish
CentOS 6.x: /etc/sysconfig/varnish
CentOS 7.x: /etc/varnish/varnish.params
Step 2:
Edit config file and add the following line:
-p http_resp_hdr_len=42000
For example:
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
 -f ${VARNISH_VCL_CONF} \
 -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
 -t ${VARNISH_TTL} \
 -p thread_pool_min=${VARNISH_MIN_THREADS} \
 -p thread_pool_max=${VARNISH_MAX_THREADS} \
 -p http_resp_hdr_len=42000 \
Save file and restart your server. The error should be gone.
- 
 In mac + brew, I didsudo /usr/local/sbin/varnishd -n /usr/local/var/varnish -f /usr/local/etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:2000 -a 127.0.0.1:80 -F -p workspace_backend=128k -p http_resp_size=256k -p http_resp_hdr_len=42000And that solves the issue. As it takes over the current terminal, I did this in new tab.Asrar– Asrar2018年09月26日 22:21:37 +00:00Commented Sep 26, 2018 at 22:21
If your are struggling with cached 503 pages that the problem is there is no setting default cache tag for Varnish cache.
There are might be two options to struggle with empty cache tags.
Open your varnish configuration *.vcl file and in section sub vcl_backend_response choose your option:
- Add disabling cache: - if (!beresp.http.X-Magento-Tags) { set beresp.ttl = 0s; set beresp.uncacheable = true; }
- Add default tag - storein case tags weren't passed:- if (!beresp.http.X-Magento-Tags) { set beresp.http.X-Magento-Tags = "store"; }
In option "1" your "wrong" cases won't be cached.
In option "2" you will be able to drop cache for 503 or other "wrong" cases.
I was moving around attributes from groups to un-assigned group in Magento 2.10, I notice I was having issue with Varnish and the error was Varnish 503 Backend Fetch Failed.
The problem was in "clean_cache_by_tags" function in Magento. I think it’s an error clearing the cache in php7 & magento2.
solution define here https://www.sohaib.com/magento-2-12-varnish-error-503-backend-fetch-failed-solved-php-7-1-nginx-varnish-5-x/
- 
 1So what is the solution? you copied part of the answer but the critical part.Mohammed Joraid– Mohammed Joraid2018年01月25日 07:26:20 +00:00Commented Jan 25, 2018 at 7:26
- 
 I've posted the solution today. It's a BUG and solved check my blog for answer sohaib.com/2018/01/26/…Sohaib Khan– Sohaib Khan2018年01月27日 04:43:53 +00:00Commented Jan 27, 2018 at 4:43
- 
 Thank you for your reply. In my case, this happened to a freshly installed MG and the issue turned to be that the server had Varnish disabled ( which I did myself earlier) while the Mag app had that setting enabled. I made sure that Varnish is disabled everywhere and the issue was solved. This was on Cloud hosting where Varnish can be disabled/enabled on both server and application level.Mohammed Joraid– Mohammed Joraid2018年01月28日 09:03:27 +00:00Commented Jan 28, 2018 at 9:03
- 
 2@SohaibKhan your solution link is not working. Can you please share correct url.Palanikumar– Palanikumar2018年01月31日 03:31:46 +00:00Commented Jan 31, 2018 at 3:31
- 
 1This is the correct link: sohaib.com/…Densen– Densen2018年06月06日 09:40:29 +00:00Commented Jun 6, 2018 at 9:40
Error is due to length of cache tags used by Magento exceed Varnish’s default of 8192 bytes. Please follow the Magento documentation to Troubleshooting 503 errors [Backend Fetch Failed errors]. https://devdocs.magento.com/guides/v2.3/config-guide/varnish/tshoot-varnish-503.html
In my situation 503 was caused by an extension I added. I've not explored the root cause but it was something to do with fetching a huge set of products on the homepage that I think was causing some sort of memory overload.
To resolve I did php bin/magento module:status to view the enabled modules.
Then I ran
php bin/magento disable Vendor_Module to disable the offending module,
followed by
php bin/magento setup:di:compile , then refresh the homepage
for me the issue got resolved when i disabled Magento CSP
php bin/magento module:disable Magento_Csp
localhost:8080?