Question

we're attempting to use Varnish to cache the results from a third party service, which we hit regularly. Unfortunately, when their service goes down our site pretty much becomes non- functional.

The issue I’m running into is that the service we connect to requires http authentication access any of the URLs we hit. I’d like to be able to set the username and password in my default.vcl file by default so that it will automatically include the authentication in every request.

Was it helpful?

Solution

So in order to solve this problem, I modified the HTTP headers like so:

sub vcl_recv {
  set req.http.Authorization = "Basic d2h5ZGlkeW91OmRlY29kZXRoaXM=";
}

The encoded part is the base64 of the username and password you want to use:

echo -n "username:password" | base64

OTHER TIPS

You can set attributes on the backend request in vcl_miss and vcl_pass.

For HTTP Basic authentication you can do something like this:

sub vcl_miss {
    if (req.backend == "backend2") {
        set bereq.http.Authorization = "Basic <base64string>";
    }
}

HTTP digest authentication on backend requests isn't supported.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top