简体   繁体   English

HTTP验证所有清漆请求

[英]HTTP authenticate all varnish requests

we're attempting to use Varnish to cache the results from a third party service, which we hit regularly. 我们正在尝试使用Varnish来缓存我们定期点击的第三方服务的结果。 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. 我遇到的问题是我们连接的服务需要http身份验证访问我们遇到的任何URL。 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. 我希望能够在默认情况下在default.vcl文件中设置用户名和密码,以便在每个请求中自动包含身份验证。

So in order to solve this problem, I modified the HTTP headers like so: 所以为了解决这个问题,我修改了HTTP头,如下所示:

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

The encoded part is the base64 of the username and password you want to use: 编码部分是您要使用的用户名和密码的base64:

echo -n "username:password" | base64

You can set attributes on the backend request in vcl_miss and vcl_pass. 您可以在vcl_miss和vcl_pass中设置后端请求的属性。

For HTTP Basic authentication you can do something like this: 对于HTTP Basic身份验证,您可以执行以下操作:

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

HTTP digest authentication on backend requests isn't supported. 不支持对后端请求的HTTP摘要身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM