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.

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top