Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

$ rpm -q varnish
$ 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

  <title>Page Unavailable</title>
    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; }
<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>

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

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 ( ! 
    || == "") {
    set = "";
  # ...


I think you don't have to mess with IPs and, you should better use curl to pass a host header to varnish (something like curl -H "Host:" 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 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;

  # 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>

  # ...

  return (deliver);




share|improve this answer

Your Answer


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.