gpt4 book ai didi

linux - Mantis 错误跟踪器的 Varnish cookie 问题

转载 作者:太空宇宙 更新时间:2023-11-04 09:38:36 25 4
gpt4 key购买 nike

我已经在我的 Linux 服务器上安装了 Varnish,并为我的网站进行了配置,包括一个 wordpress 站点 (www.mywordpress.com),它工作正常。现在我已经在我的网站 (www.mywordpress.com/mantis) 下安装了 mantis bug tracker。但是当我尝试以默认用户(管理员/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;

}

}

最佳答案

首先,改变它,取消设置任何不在 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;
}

(其中 '||' 表示或,'~' 表示等于约,'req.url' - 请求的 URL)

并且在vcl_recv中(不管放在哪里,放在开头),忽略缓存/mantis URLs:

sub vcl_recv {

...

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

...
}

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

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

关于linux - Mantis 错误跟踪器的 Varnish cookie 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23742243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com