4

I getting this error how can i do? i try to editing many time but still not work.

Error 503 Backend fetch failed
Backend fetch failed

Guru Meditation:
XID: 35

Varnish cache server

My CentOS 7: /etc/varnish/varnish.params

# Varnish environment configuration description. This was derived from # the old style sysconfig/defaults settings

# Set this to 1 to make systemd reload try to switch VCL without restart. RELOAD_VCL=1

# Main configuration file. You probably want to change it. VARNISH_VCL_CONF=/etc/varnish/default.vcl

# Default address and port to bind to. Blank address means all IPv4 # and IPv6 interfaces, otherwise specify a host name, an IPv4 dotted # quad, or an IPv6 address in brackets. # VARNISH_LISTEN_ADDRESS=192.168.1.5 VARNISH_LISTEN_PORT=80

# Admin interface listen address and port VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1 VARNISH_ADMIN_LISTEN_PORT=6082

# Shared secret file for admin interface VARNISH_SECRET_FILE=/etc/varnish/secret

# Backend storage specification, see Storage Types in the varnishd(5) # man page for details. VARNISH_STORAGE="malloc,1024M"

# User and group for the varnishd worker processes VARNISH_USER=varnish VARNISH_GROUP=varnish

# Other options, see the man page varnishd(1) DAEMON_OPTS="-a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,1024m -p thread_pool_min=5 -p thread_pool_max=500 -p thread_pool_timeout=300 -p http_resp_hdr_len=65536 -p http_resp_size=98304 -p workspace_backend=98304"

update:

1) Yes, the vcl file generated by Magento.

2)

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4338/varnishd

tcp 0 0 127.0.0.1:6082 0.0.0.0:* LISTEN 4337/varnishd

tcp6 0 0 :::80 :::* LISTEN 4338/varnishd

tcp6 0 0 :::8080 :::* LISTEN 3905/httpd

3) i in vcl edited added http:// beacuse when i only /pub/health_check.php will be 503, but added http:// the theme look like something wrong no css.

.probe = {. url = "http://example.com/pub/health_check.php";

4) i used this command

curl -I -v --location-trusted 'http://example.com'

show this, but i dont know working or not working, beacuse the var/page_cache/ directory is not empty. the mage-tags file still here.

< X-Magento-Cache-Control: max-age=0, must-revalidate, no-cache,no-store

X-Magento-Cache-Control: max-age=0, must-revalidate,no-cache, no-store < Age: 0 Age: 0 <

X-Magento-Cache-Debug: MISS

X-Magento-Cache-Debug: MISS

1
  • you can not connect to backend. let's edit file /etc/varnish/default.vcl. Find line .url = "/pub/health_check.php", then change it .url = "/"; or .url = "/health_check.php"; Mar 12, 2020 at 9:11

3 Answers 3

4

After compared with the /etc/varnish/default.vcl, I found after removing the .probe section in the backend default can solve this. Still wondering why the probe caused this

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

to

backend default {
    .host = "127.0.0.1";
    .port = "8080";
    .first_byte_timeout = 600s;
}

Updated:

Just change the following line:

.url = "/pub/health_check.php";

to

.url = "/health_check.php";

solved the problem, refer to this article https://www.sohaib.com/magento-2-12-varnish-error-503-backend-fetch-failed-solved-php-7-1-nginx-varnish-5-x/

1

There are some possibilities to your error. I follow this tutorial (Solution 2) and successfully fix the error: https://magentip.com/magento-2-error-503-backend-fetch-failed-with-varnish-cache/

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

We will change http_resp_hdr_len value in Varnish configuration file. (Maximum length of any HTTP backend response header

The path to varnish configuration file is

-Ubuntu: /etc/default/varnish

-Centos 6 : /etc/sysconfig/varnish

-Centos 7: /etc/varnish/varnish.params

change the http_resp_hdr_len value (located in line 101 after thread_pool_max ) to

-p http_resp_hdr_len=70000 \

Also, change http_resp_size to

-p http_resp_size=100000 \

2. Wrong health_check.php location in Varnish config file

Go to Varnish configuration file (/etc/varnish/default.vcl) and find these lines

.probe = {
    .url = "/pub/health_check.php";

Change it to

.probe = {
    .url = "/health_check.php";
1
  • Changing the http_resp_hdr_len and http_resp_size in the init systemd configuration (/lib/systemd/system/varnish.service) worked for me. Thanks!
    – PauGNU
    Jan 26, 2021 at 9:01
0

"Error 503 Backend fetch failed" errors usually mean two things:

  • Varnish is not able to fetch the response from Magento due to configuration issues
  • There is an issue on Magento side. Magento sends 5xx HTTP response code.

Varnish configuration issues

There are bunch of configuration issues, but most common are:

  • default default.vcl file is used. Make sure you take the vcl file generated by Magento
  • wrong backend specified in vcl file. Check the port and ip address specified in vcl file. I found netstat -tnulp useful tool to check the running services and their ports
  • Your Magento instance is not in web_root. Check every relative path in vcl file and add corresponding prefixes(health check file, media files...).

You need to restart varnish after every change.

Magento related issues

Usually, they are about some file permissions. In order to find exact issue, you need to skip varnish and visit the web server directly - http://your_domain.com:{web_server_port}/. Then you can turn on Magento developer mode in console using ./bin/magento deploy:mode:set developer command and uncomment ini_set('display_errors', 1); line in app/bootstrap.php. After all these actions you should see the exact error message

10
  • I updated original post 1,2,3,4, please check,thank you
    – niceonelee
    Dec 29, 2017 at 17:05
  • You have magento2 chunk in URL. Just add magento2/ prefix to all relative paths in vcl file. E.g. probe_url = domain.com/magento2/pub/health_check. Also, make sure you switch page cache to varnish in magento admin panel Dec 29, 2017 at 17:11
  • but added http:// the theme look like something wrong no css. And no, my magento in public_html , domain.com/magento2 <-is for exsample. What is your mean? switch page cache to varnish in magento admin panel ? is Cache Management? thank you
    – niceonelee
    Dec 29, 2017 at 17:16
  • sorry what is switch page cache to varnish in magento admin panel ? is Cache Management? thank you
    – niceonelee
    Dec 29, 2017 at 17:38
  • The setting is located in Stores -> Configuration -> Advanced -> System -> Full Page Cache. There is no need to specify http before paths. Instead, it should be the relative path to Magento. Jan 2, 2018 at 10:03

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.