0

I have a 503 Error with multiple host in varnish 4 with WordPress 4.4.

Virtual Server, to server_1 and server_2. (I copy only one, because the VS is the same for both, x is equal to server number).

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;
}

When i try enter in any server i get 503 Backend fetch failed, but when i enter by separate server (http://server_1.localhost and http://server_2.localhost) return 200 code.

Rickest Rick
  • 1,519
  • 1
  • 15
  • 28
kalelc
  • 1,507
  • 1
  • 18
  • 33

1 Answers1

0

Varnish tests backend healthy via GET /. And backend's IP is 127.0.0.1 Try to log in on your server and do "get /" via console web browser, like elinks(apt-get install elinks or yum install elinks, if you don't have it): elinks http://127.0.0.1:81 When I've done that on my server, with the same problem, I've noticed that there was no default web page for 127.0.0.1, and Varnish got an error 404 and marked the backend as bad. Hope this would help