1
votes

We have varnish configured as below:

  • we have probe validation with apache host and port, but using a context to a backend (application server / mod jk).
  • we are not using cluster and load balance configuration.

    backend default {
        .host = "127.0.0.1";
        .port = "80";
        .max_connections = 300;

        .probe = {
            .url = "/webapp-context/healthcheck";
            .interval  = 60s;
            .timeout   = 20s;
            .window    = 5;
            .threshold = 3;
        }

        .first_byte_timeout     = 5s;
        .connect_timeout        = 5s;
        .between_bytes_timeout  = 1s;
    }

  • we have varnish cache only for specific contexts
  • we dont have varnish cache for staticfiles (www.domain.com/staticfiles/*), because all static files are on DocumentRoot (Apache).
    sub vcl_recv {

        // do not cache static files
        if ( req.url ~ "^(/staticfiles)" ) {
            return(pass);
        }



        // create cache
        if ( req.url ~ "^(/content/)" ) {
            unset req.http.Cookie;
            return(hash);
        }

        ...
        ...
    }

So, my problem is: we have configured varnish to do "pass" for the static files context. And now, when our backend is sick after a probe validation, all staticfiles context is getting HTTP 503 error, but the html pages are still ok on Varnish cache, but without staticfiles.

Are there any way to configure Varnish to keep serving all static files from Apache, even that the application server is down?

1

1 Answers

1
votes

You can setup additional backend definition that will not have health check specified. So your VCL will include something like this:

backend static {
    .host = "127.0.0.1";
    .port = "80";
    .max_connections = 300;
}

# .. your default backend with probe here

sub vcl_recv {
    # ...
    // do not cache static files
    if ( req.url ~ "^(/staticfiles)" ) {
        set req.backend_hint = static;
        return(pass);
    }
    # ,,,
}