2

EDIT(1): The ".timeout" value does not seem to have any effect. The "503 Backend fetch failed" error is displayed immediately

Original Explanation: I am quite new with varnish. Any help is appreciated. I keep getting the below error every time I try to call my webpage with Varnish:

<body>
    <h1>Error 503 Backend fetch failed</h1>
    <p>Backend fetch failed</p>
    <h3>Guru Meditation:</h3>
    <p>XID: 3</p>
    <hr>
    <p>Varnish cache server</p>
</body>

Background: : I have a file index.php:

The below works:

curl --header "Host: serverx.dev" 192.168.56.10:8080/index.php    

The below does not work and throws "Backend fetch failed" error:

curl --header "Host: serverx.dev" 192.168.56.10:80/index.php    

I use the following:

Virtualbox 5.0.32 r112930
Host operating system: Windows 7 (64-bit)
Guest operating system: Debian Jessie (minimal install)
Apache2   -----port 8080
varnish-4.1.5 revision 2c82b1c   -----port 80

default.vcl:

vcl 4.0;
# import default varnish library
import std;
import directors;
backend server1 {
    .host = "192.168.56.10";
    .port = "8080";
    .probe = {
        .url = "/robots.txt";
        .interval = 5s;
        .timeout = 50s;
        .window = 5;
        .threshold = 3;
    }
}
sub vcl_init {
    new cluster = directors.round_robin();
    cluster.add_backend(server1);
}

The following is the current varnish status:

root@debian:/etc/varnish# ps -ef | grep varnish
varnish   4210     1  0 11:26 ?        00:00:00 /usr/sbin/varnishd -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
vcache    4211  4210  0 11:26 ?        00:00:00 /usr/sbin/varnishd -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
root      4632  1470  0 11:40 pts/0    00:00:00 grep varnish

and also:

root@debian:/etc/varnish# netstat -anp | grep varnish
tcp        0      0 127.0.0.1:6082          0.0.0.0:*               LISTEN      4210/varnishd
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4210/varnishd
tcp6       0      0 ::1:6082                :::*                    LISTEN      4210/varnishd
tcp6       0      0 :::80                   :::*                    LISTEN      4210/varnishd
unix  2      [ ]         DGRAM                    35213    4210/varnishd

Apache2:

root@debian:/etc/varnish# netstat -anp | grep apache2
tcp6       0      0 :::443                  :::*                    LISTEN      4461/apache2
tcp6       0      0 :::8080                 :::*                    LISTEN      4461/apache2

Varnishlog gives following output

-   BereqHeader    X-Varnish: 51
-   VCL_call       BACKEND_FETCH
-   VCL_return     fetch
-   FetchError     Director cluster returned no backend
-   FetchError     No backend
-   Timestamp      Beresp: 1490091185.165509 0.000027 0.000027
-   Timestamp      Error: 1490091185.165513 0.000030 0.000004
-   BerespProtocol HTTP/1.1
-   BerespStatus   503
-   BerespReason   Service Unavailable
-   BerespReason   Backend fetch failed
-   BerespHeader   Date: Tue, 21 Mar 2017 10:13:05 GMT
-   BerespHeader   Server: Varnish
-   VCL_call       BACKEND_ERROR

I would be glad to provide more info.

Preethi
  • 73
  • 1
  • 6
  • 1
    Could you run the following command and post the result? `varnishadm backend.list` Also could you post the whole vcl file if it is not complete yet? – alejdg Mar 21 '17 at 21:22
  • @alejdg - The result for varnishadm backend.list is as follows: root@debian:/home/preethi# varnishadm backend.list Backend name Admin Probe boot.server1 probe Sick 0/5 – Preethi Mar 22 '17 at 09:39
  • I could not post the entire default.vcl file because of copyright problem. The same file actually worked in another server so I deduced the problem was only in the server setup. – Preethi Mar 22 '17 at 09:41
  • You are using a director with only one backend. The varnishlog tells you that you don't have any backend in your director. Why don't you use the backend without the director? Other than that, can you try without the probe? It's not recommended but I may think that your settings are quite loose (50sec to fetch a local txt file). – Benjamin Baumann Mar 22 '17 at 09:59
  • Thanks @BenjaminBaumann . The problem was in the probe. – Preethi Mar 22 '17 at 10:40

1 Answers1

0

The problem seemed to be in the default.vcl. After changing the .url value in .probe , varnish works properly.

Before:

backend server1 {
    .host = "192.168.56.10";
    .port = "8080";
    .probe = {
        .url = "/robots.txt";
        .interval = 5s;
        .timeout = 50s;
        .window = 5;
        .threshold = 3;
    }
}

Now:(This one works)

backend server1 {
    .host = "192.168.56.10";
    .port = "8080";
    .probe = {
        .url = "/";        -------The change was made here
        .interval = 5s;
        .timeout = 50s;
        .window = 5;
        .threshold = 3;
    }
}
Preethi
  • 73
  • 1
  • 6