Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using Varnish-3.0.5 on Scientific Linux 6.4 (64bit):

$ rpm -q varnish
varnish-3.0.5-1.el5.centos.x86_64
$ cat /etc/redhat-release 
Scientific Linux release 6.4 (Carbon)
$ uname -a
Linux XXX.XXX.XXX 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 11:13:47 CDT 2013 x86_64 x86_64 x86_64 GNU/Linux
$ curl XXX.XX.XX.XXX

<html>
<head>
  <title>Page Unavailable</title>
  <style>
    body { background: #303030; text-align: center; color: white; }
    #page { border: 1px solid #CCC; width: 500px; margin: 100px auto 0; padding: 30px; background: #323232; }
    a, a:link, a:visited { color: #CCC; }
    .error { color: #222; }
  </style>
</head>
<body onload="setTimeout(function() { window.location = '/' }, 5000)">
  <div id="page">
    <h1 class="title">Page Unavailable</h1>
    <p>The page you requested is temporarily unavailable.</p>
    <p>We're redirecting you to the <a href="/">homepage</a> in 5 seconds.</p>
    <div class="error">(Error 503 Service Unavailable)</div>
  </div>
</body>
</html>
$ 

I trying to figure out how I can configure default virtual-host as I'm getting Error 503 Service Unavailable if at least one of my back-end(s) is down whenever I run curl against IP address. Do I need to specify IP address in req.http.host as well inside of vcl_recv() in order for me to stop getting 503? or how else do I specify which virtual-host is default?

share|improve this question
    
So you want Varnish to not serve the response to the client (and instead try another backend) if it gets that 503 response from the backend, correct? –  Shane Madden Dec 6 '13 at 7:21

1 Answer 1

Fist of all let me say that it's quite difficult to give advices without seen your actual VCL config.

To respond your actual question

You can set a default host at the beginning of your vcl_recv, note that your backend(s) should be configured to respond to that exact host

sub vcl_recv {
  /* set a default host if no host is provided on the request or if it is empty */
  if ( ! req.http.host 
    || req.http.host == "") {
    set req.http.host = "your.default.host.tld";
  }
  # ...

}

I think you don't have to mess with IPs and req.http.host, you should better use curl to pass a host header to varnish (something like curl -H "Host: your.default.host.tld" http://XX.XX.XX.XXX/)


Some general suggestions on the topic:

Add misbehaving control logic to your VCL [1]

Are you setting your backend correctly?

Remember that varnish will uses "default" backend (or director) unless instructed to use other on your VCl logic

Add health probes and see what backends are failing

Use consistent health probes [2] and use commandline command varnishadm debug.health see the docs for a better understanding [3]

Add a restart logic to your vlc error

Something like this

sub vcl_error {
  # ...

  /* Try to restart request in case of failure */
  if (obj.status == 503 && req.restarts < 5) {
    set obj.http.X-Restarts = req.restarts;
    return(restart);
  }

  # Before any deliver
  return (deliver);
}

Add debug logic to your vlc error synthetic response

Remember that you can add debug headers on vcl_fetch passing backend error code to your varnish error response:

sub vcl_fetch {
  # ...

  set beresp.http.X-Debug-Backend-Code = beresp.status;

  # ...
}
sub vcl_error {
  # ...

  synthetic {""
  # Insert the following at the end of your current response
  <p>Backend Status code was "} + obj.http.X-Debug-Backend-Code + {"</p>
    </body>
  </html>
  "};

  # ...

  return (deliver);
}

[1] https://www.varnish-cache.org/docs/3.0/tutorial/handling_misbehaving_servers.html

[2] https://www.varnish-cache.org/docs/3.0/reference/vcl.html#backend-probes

[3] https://www.varnish-cache.org/trac/wiki/BackendPolling#CLIcommands

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.