清漆和摘要认证导致uri不匹配

时间:2014-09-19 10:30:22

标签: apache varnish digest-authentication http-status-code-400

我在同一个虚拟服务器上设置了实时网站和暂存版本。实时站点使用Varnish并且不进行身份验证,暂存站点绕过Varnish但使用摘要式身份验证。在我的VCL文件中,我有这个:

sub vcl_recv {
    if (req.http.Authorization || req.http.Authenticate) {
        return(pass);
    }

    if (req.http.host != "live.site.com") {
        return(pass);
    }

我在暂存网站上发现了一个问题,即没有提供任何查询字符串的资源 - 在Firebug中我看到了400个错误的请求'并在Apache中记录:

[Fri Sep 19 11:13:03 2014] [error] [client 127.0.0.1] Digest: uri mismatch - 
    </wp-content/plugins/jetpack/modules/wpgroho.js?ver=3.9.2> does not match 
    request-uri </wp-content/plugins/jetpack/modules/wpgroho.js>, referer: 
    http://stage.site.com/

我做错了什么,有谁知道如何解决这个问题?

谢谢,

托比

1 个答案:

答案 0 :(得分:0)

好的,发现它,这就是我找到的东西(万一它可以帮助其他人):

我当然在我的Varnish VCL中有一个部分可以从静态文件中删除查询字符串,以帮助缓存:

if (req.request ~ "^(GET|HEAD)$" && req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)(\?.*)?$") {
    if (req.url ~ "nocache") {
        return(pass);
    }
    set req.url = regsub(req.url, "\?.*$", "");
    unset req.http.Cookie;
    set req.grace = 2m;
    return(lookup);
}

这明显与摘要认证冲突,所以我将不得不重新审视VCL的那部分。

更新我刚刚将第二个条件更改为:

    if (req.http.Authorization || req.http.Authenticate || 
        req.url ~ "nocache") {
        return(pass);
    }