【问题标题】:503 Backend fetch failed with varnish 4.1 and WordPress 4.4503 后端获取失败,varnish 4.1 和 WordPress 4.4
【发布时间】:2016-04-20 10:20:00
【问题描述】:

varnish 4WordPress 4.4 中的多个主机出现 503 错误。

虚拟服务器,到 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 *;
  }
}

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 Backend fetch failed,但是当我通过单独的服务器(http://server_1.localhosthttp://server_2.localhost)进入时返回 200 代码。

【问题讨论】:

    标签: wordpress varnish varnish-4


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-17
      • 2018-12-20
      • 1970-01-01
      • 1970-01-01
      • 2015-07-16
      • 2016-06-19
      • 2023-04-01
      • 2021-12-17
      相关资源
      最近更新 更多