与螳螂bug跟踪器的清漆饼干问题

时间:2014-05-19 15:58:43

标签: linux wordpress cookies varnish mantis

我已经在我的Linux服务器上安装了Varnish并为我的网站配置了包括wordpress网站(www.mywordpress.com),它运行正常。现在我在我的网站(www.mywordpress.com/mantis)下安装了螳螂bug跟踪器。但是当我尝试以默认用户(管理员/ root)登录MantisBT时,它会显示错误,例如“您的浏览器不知道如何处理cookie,或拒绝处理它们”。如何为Mantis url设置Varnish例外或允许cookie(在default.vcl中)。我的default.vcl文件如下所示:


###my default.vcl file:
backend default {
.host = "127.0.0.1";
.port = "8080";
}
backend master {
.host = "127.0.0.1";
.port = "8080";
}
acl purge {
    "localhost";
}
sub vcl_recv {
if (req.request == "PURGE") {
    if (!client.ip ~ purge) {
        error 405 "Not allowed.";
    }
    return(lookup);
}
if (req.restarts == 0) {
    if (req.http.x-forwarded-for) {
        set req.http.X-Forwarded-For =
        req.http.X-Forwarded-For + ", " + client.ip;
    } else {
        set req.http.X-Forwarded-For = client.ip;
    }
}


### do not cache these files:
if (req.url ~ "/svn" || req.http.Authorization || req.http.Authenticate)
{
    return (pass);
}

##never cache the admin pages, or the server-status page
if (req.url ~ "wp-(admin|login)" || req.http.Content-Type ~ "multipart/form-data")
{
    set req.backend = master;
    return(pass);
}

if (req.url ~ "opportunity-attachments" || req.http.Content-Type ~ "multipart/form-data")
{
    set req.backend = master;
    return(pass);
}

if (req.url ~ "^phpmyadmin") {
    set req.backend = master;
    return(pipe);
}

if (req.url ~ "^/login") {
    set req.backend = master;
    return(pipe);
}

## always cache these images & static assets
if (req.request == "GET" && req.url ~ "\.(css|js|gif|jpg|jpeg|bmp|png|ico|img|tga|wmf)$") {
    remove req.http.cookie;
    return(lookup);
}
if (req.request == "GET" && req.url ~ "(xmlrpc.php|wlmanifest.xml)") {
    remove req.http.cookie;
    return(lookup);
}

#never cache POST requests
if (req.request == "POST")
{
    return(pass);
}
#DO cache this ajax request
if(req.http.X-Requested-With == "XMLHttpRequest" && req.url ~ "recent_reviews")
{
    return (lookup);
}

#dont cache ajax requests
if(req.http.X-Requested-With == "XMLHttpRequest" || req.url ~ "nocache" || req.url ~ "(control.php|wp-comments-post.php|wp-login.php|bb-login.php|bb-reset-password.php|register.php)")
{
    return (pass);
}

if (req.http.Cookie && req.http.Cookie ~ "wordpress_") {
    set req.http.Cookie = regsuball(req.http.Cookie, "wordpress_test_cookie=", "; wpjunk=");
}
### don't cache authenticated sessions
if (req.http.Cookie && req.http.Cookie ~ "(wordpress_|PHPSESSID)") {
    return(pass);
}

### parse accept encoding rulesets to make it look nice
if (req.http.Accept-Encoding) {
    if (req.http.Accept-Encoding ~ "gzip") {
        set req.http.Accept-Encoding = "gzip";
    } elsif (req.http.Accept-Encoding ~ "deflate") {
        set req.http.Accept-Encoding = "deflate";
    } else {
        # unkown algorithm
        remove req.http.Accept-Encoding;
    }
}


if (req.http.Cookie)
{
    set req.http.Cookie = ";" + req.http.Cookie;
    set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
    set req.http.Cookie = regsuball(req.http.Cookie, ";(vendor_region|PHPSESSID|themetype2)=", "; \1=");
    set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
    set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");

    if (req.http.Cookie == "") {
        remove req.http.Cookie;
    }
}

if (req.url ~ "^/$") {
    unset req.http.cookie;
}
return(lookup);
}

sub vcl_hit {
if (req.request == "PURGE") {
    set obj.ttl = 0s;
    error 200 "Purged.";
 }
}
sub vcl_miss {
if (req.request == "PURGE") {
    error 404 "Not in cache.";
}
if (!(req.url ~ "wp-(login|admin)")) {
    unset req.http.cookie;
}

if (req.url ~ "^/[^?]+.(jpeg|jpg|png|gif|ico|js|css|txt|gz|zip|lzma|bz2|tgz|tbz|html|htm)(\?.|)$") {
    unset req.http.cookie;
    set req.url = regsub(req.url, "\?.$", "");
}
if (req.url ~ "^/$") {
    unset req.http.cookie;
}

}
sub vcl_fetch {
if (req.url ~ "^/$") {
    unset beresp.http.set-cookie;
}
if (!(req.url ~ "wp-(login|admin)")) {
    unset beresp.http.set-cookie;

}

}

1 个答案:

答案 0 :(得分:2)

首先,改变这一点,它取消了任何不在wp-login或wp-admin中的cookie:

if (!(req.url ~ "wp-(login|admin)")) {
    unset req.http.cookie;
}

这样的事情:

if (!(req.url ~ "wp-(login|admin)") || !(req.url ~ "mantis")) {
    unset req.http.cookie;
}

(其中'||'表示OR,'〜'表示等于about,'req.url'表示请求的URL)

并在vcl_recv中(无论在哪里,将其置于开始),忽略缓存/mantis网址:

sub vcl_recv {

    ...

    if (req.url ~ "/mantis")
    {
        return (pass);
    }

    ...
}

并重新启动varnish(通常是 ubuntu 上的sudo service varnish restart)。再次检查它应该没问题(如果它不工作,清理浏览器的cookie和缓存)。

...而且,为什么mantis不在wp-admin目录中?它是一个wordpress插件吗?