0

我有一个 503 错误,其中包含多个varnish 4主机WordPress 4.4

虚拟服务器,到server_1server_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.localhosthttp://server_2.localhost)输入时返回200代码。

4

1 回答 1

0

Varnish 通过 GET / 测试后端是否健康。并且后端的 IP 是 127.0.0.1 尝试登录您的服务器并通过控制台 Web 浏览器执行“get /”,例如 elinks(apt-get install elinks 或 yum install elinks,如果您没有它): elinks http: //127.0.0.1:81 当我在我的服务器上这样做时,同样的问题,我注意到没有 127.0.0.1 的默认网页,并且 Varnish 得到一个错误 404 并将后端标记为坏. 希望这会有所帮助

于 2016-01-21T17:19:26.333 回答