我有一个 503 错误,其中包含多个varnish 4
主机WordPress 4.4
。
虚拟服务器,到server_1和server_2。(我只复制一个,因为两者的VS相同,x等于服务器编号)。
server {
listen 81;
server_name server_x.localhost;
root /var/www/server_x;
index index.html index.php;
error_page 404 /404.html;
# Use gzip compression
# .....
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm-server_x.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* \.(eot|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}
}
默认.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 Backend fetch failed,但是当我通过单独的服务器(http://server_1.localhost
和http://server_2.localhost
)输入时返回200
代码。