503后端获取失败,varnish 4.1和WordPress 4.4
我在503后端获取失败,varnish 4.1和WordPress 4.4,wordpress,varnish,varnish-4,Wordpress,Varnish,Varnish 4,我在varnish 4和WordPress 4.4中有一个503多主机错误 虚拟服务器,到服务器1和服务器2。(我只复制一个,因为两者的VS相同,x等于服务器号) default.vcl vcl 4.0; backend server_1{ .host = "127.0.0.1"; .port = "81"; .probe = { .url = "/"; .interval = 5s; .timeout = 2s; .window = 5;
varnish 4
和WordPress 4.4
中有一个503多主机错误
虚拟服务器,到服务器1和服务器2。(我只复制一个,因为两者的VS相同,x等于服务器号)
default.vcl
vcl 4.0;
backend server_1{
.host = "127.0.0.1";
.port = "81";
.probe = {
.url = "/";
.interval = 5s;
.timeout = 2s;
.window = 5;
.threshold = 3;
}
}
backend server_2{
.host = "127.0.0.1";
.port = "81";
.probe = {
# the same of server_1
}
}
acl purge {
"localhost";
"127.0.0.1";
}
sub vcl_recv {
if (req.http.host ~ "server_1.localhost") {
set req.backend_hint = server_1;
}
elseif (req.http.host ~ "server_2.localhost") {
set req.backend_hint = server_2;
}
if (req.method == "PURGE") {
if (!client.ip ~ purge) {
return(synth(405,"Not allowed."));
}
return (purge);
}
if (req.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
unset req.http.cookie;
set req.url = regsub(req.url, "\?.*$", "");
}
if (req.url ~ "\?(utm_(campaign|medium|source|term)|adParams|client|cx|eid|fbid|feed|ref(id|src)?|v(er|iew))=") {
set req.url = regsub(req.url, "\?.*$", "");
}
if (req.url ~ "wp-(login|admin)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php") {
return (pass);
}
if (req.http.cookie) {
if (req.http.cookie ~ "(wordpress_|wp-settings-)") {
return(pass);
} else {
unset req.http.cookie;
}
}
return(hash);
}
sub vcl_backend_response {
if ( (!(bereq.url ~ "(wp-(login|admin)|login)")) || (bereq.method == "GET") ) {
unset beresp.http.set-cookie;
set beresp.ttl = 1h;
}
if (bereq.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
set beresp.ttl = 365d;
}
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
set resp.http.X-Hits = obj.hits;
}
当我尝试输入任何服务器时,我得到的503后端获取失败,但当我通过单独的服务器输入时(
http://server_1.localhost
和http://server_2.localhost
)返回200
code.通过GET/检查后端是否健康。后端的IP是127.0.0.1
尝试登录您的服务器并通过控制台web浏览器执行“get/”,如eLink(如果您没有,请使用apt get install eLink或yum install eLink):
埃林克斯
当我在我的服务器上完成这项工作时,我发现127.0.0.1没有默认的web页面,Varnish出现错误404并将后端标记为坏。
希望这能有所帮助
vcl 4.0;
backend server_1{
.host = "127.0.0.1";
.port = "81";
.probe = {
.url = "/";
.interval = 5s;
.timeout = 2s;
.window = 5;
.threshold = 3;
}
}
backend server_2{
.host = "127.0.0.1";
.port = "81";
.probe = {
# the same of server_1
}
}
acl purge {
"localhost";
"127.0.0.1";
}
sub vcl_recv {
if (req.http.host ~ "server_1.localhost") {
set req.backend_hint = server_1;
}
elseif (req.http.host ~ "server_2.localhost") {
set req.backend_hint = server_2;
}
if (req.method == "PURGE") {
if (!client.ip ~ purge) {
return(synth(405,"Not allowed."));
}
return (purge);
}
if (req.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
unset req.http.cookie;
set req.url = regsub(req.url, "\?.*$", "");
}
if (req.url ~ "\?(utm_(campaign|medium|source|term)|adParams|client|cx|eid|fbid|feed|ref(id|src)?|v(er|iew))=") {
set req.url = regsub(req.url, "\?.*$", "");
}
if (req.url ~ "wp-(login|admin)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php") {
return (pass);
}
if (req.http.cookie) {
if (req.http.cookie ~ "(wordpress_|wp-settings-)") {
return(pass);
} else {
unset req.http.cookie;
}
}
return(hash);
}
sub vcl_backend_response {
if ( (!(bereq.url ~ "(wp-(login|admin)|login)")) || (bereq.method == "GET") ) {
unset beresp.http.set-cookie;
set beresp.ttl = 1h;
}
if (bereq.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
set beresp.ttl = 365d;
}
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
set resp.http.X-Hits = obj.hits;
}