使用Varnish缓存经过身份验证的资源

时间:2013-11-25 13:41:17

标签: authentication caching resources vcl varnish

我们公司在内部使用一个应用程序,为所有经过身份验证的用户提供或多或少的静态内容。构建应用程序使其所有资源(js,css,图像,html页面)都经过身份验证。可悲的是,我似乎无法让Varnish为缓存经过身份验证的资源而工作。如果我使资源未经身份验证并使用以下VCL配置,则可以正常工作:

backend default {
  .host = "****";
  .port = "****";
}

sub vcl_recv {
    if (req.url ~ "^/js" || req.url ~ "^/css" || req.url ~ "^/images") {
            unset req.http.cookie;
    }    
}
sub vcl_fetch {
    if (req.url ~ "^/js" || req.url ~ "^/css" || req.url ~ "^/images") {
            unset beresp.http.set-cookie;
    }
}

但是,我正在寻找缓存,尽管资源经过身份验证,我理解这不是Varnish的默认行为。尝试

if (req.http.Authorization) {
        return(lookup);
}
vcl_recv中的

没有帮助。取消设置授权标头也无济于事(应用程序的身份验证搞砸了)。

我得到以下清漆日志(b-后端调用仍然发生):

14 TxURL        b /_search
14 TxHeader     b Content-Type: application/x-www-form-urlencoded
15 RxURL        c /_search
15 RxHeader     c Content-Type: application/x-www-form-urlencoded
14 TxURL        b /admin
14 TxHeader     b Content-Type: application/x-www-form-urlencoded
17 RxURL        c /admin
17 RxHeader     c Content-Type: application/x-www-form-urlencoded
15 RxURL        c /_search
15 RxHeader     c Content-Type: application/x-www-form-urlencoded
17 RxURL        c /admin
17 RxHeader     c Content-Type: application/x-www-form-urlencoded
14 TxURL        b /js/all.js?_=1385100392830
17 RxURL        c /js/all.js?_=1385100392830

添加HTTP请求和响应标头:

请求标题:

Host: ****.com
Connection: keep-alive
Authorization: Negotiate YIIVTAYGKwYBBQUCoIIVQDCCFTygMDAuBgkqhkiC9xIBAgIGCSqGSIb3EgECAgYKK
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
Referer: ****
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8

响应标题:

Cache-Control: public, max-age=86400
Transfer-Encoding: chunked
Content-Type: application/x-javascript
Content-Encoding: gzip
Last-Modified: Sat, 10 Nov 2012 08:32:01 GMT
Accept-Ranges: bytes
ETag: "{6B28BC5E-71C3-4A1B-9D3C-1DA5EA161F96},2pub"
Vary: Accept-Encoding
Server: Microsoft-IIS/7.5
SPRequestGuid: 8864bca5-d7cb-4ac0-bbe8-3a64391ca70f
X-AspNet-Version: 2.0.50727
WWW-Authenticate: Negotiate oYGzMIGwoAMKAQChCwYJKoZIgvcSAQICooGbBIGYYIGVBgkqhkiG9xIBAgICAG+BhTCBgqADAgEFoQMCAQ+idjB
Persistent-Auth: true
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 14.0.0.6137
X-MS-InvokeApp: 1; RequireReadOnly
Date: Tue, 26 Nov 2013 15:43:46 GMT

有人可以提供一个可以提供帮助的VCL配置代码段吗?

0 个答案:

没有答案
相关问题