0

Here's the default.vcl, varnish configuration file, that I've built after lots of reading and referring:

backend default {
  .host = "127.0.0.1";
  .port = "8080";
}

acl purge {
  "localhost";
}


# Called when a request is received
sub vcl_recv {

  if (req.request == "BAN") {
    if(!client.ip ~ purge) {
      error 405 "Not allowed.";
    }
    ban("req.url ~ "+req.url+" && req.http.host == "+req.http.host);
    error 200 "Banned.";
  }

  if (req.request != "GET" &&
      req.request != "HEAD" &&
      req.request != "PUT" &&
      req.request != "POST" &&
      req.request != "TRACE" &&
      req.request != "OPTIONS" &&
      req.request != "DELETE") {
    return (pipe);
  }

  if (req.request != "GET" && req.request != "HEAD") {
    return (pass);
  }

  #Requests for login, admin, sign up, preview, password protected posts, admin-ajax or other ajax requests
  if (req.url ~ "(wp-login|wp-admin|wp-signup|preview=true|admin-ajax.php)" || req.http.Cookie ~ "(wp-postpass|wordpress_logged_in|comment_author_)" || req.http.X-Requested-With == "XMLHttpRequest" || req.url ~ "nocache" || req.url ~ "(control.php|wp-comments-post.php|wp-login.php|bb-login.php|bb-reset-password.php|register.php)") {
    return (pass);
  }

  remove req.http.cookie;
  return (lookup);

}


# Called after a document has been successfully retrieved from the backend
sub vcl_fetch {

  if (beresp.status == 404 || beresp.status == 503 || beresp.status >= 500) {
    set beresp.ttl = 0m;
    return(hit_for_pass);
  }

  # Requests for login, admin, sign up, preview, password protected posts, admin-ajax or other ajax requests
  if (req.url ~ "(wp-login|wp-admin|wp-signup|preview=true|admin-ajax.php)" || req.http.Cookie ~ "(wp-postpass|wordpress_logged_in|comment_author_)" || req.http.X-Requested-With == "XMLHttpRequest" || req.url ~ "nocache" || req.url ~ "(control.php|wp-comments-post.php|wp-login.php|bb-login.php|bb-reset-password.php|register.php)") {
    return (hit_for_pass);
  }

  # Don't cache .xml files (e.g. sitemap)
  if (req.url ~ "\.(xml)$") {
    set beresp.ttl   = 0m;
  }

  # Cache HTML
  # if (req.url ~ "\.(html|htm)$") {
  #   set beresp.ttl   = 60m;
  # }

  remove beresp.http.set-cookie;
  set beresp.ttl = 24h;
  return (deliver);

}

Having saved the file, this is what happened when I tried restarting varnish:

user@host:~$ sudo service varnish restart
 * Stopping HTTP accelerator varnishd                                                                                          [fail] 
 * Starting HTTP accelerator varnishd                                                                                          [fail] 
Message from VCC-compiler:
Syntax error at
('input' Line 62 Pos 19)
    set beresp.ttl   = 0m;
------------------#---------

Running VCC-compiler failed, exit 1

VCL compilation failed

It essentially implies that something's wrong with this line in my default.vcl:

# Don't cache .xml files (e.g. sitemap)
if (req.url ~ "\.(xml)$") {
  set beresp.ttl   = 0m;
}

But I am not sure what it is. What am I doing wrong here?

0

1 Answer 1

2

The error is due to extra spaces on line 62, starting at position 19 in the configuration (default.vcl), just as clearly indicated in the error:

    set beresp.ttl   = 0m;
------------------#---------

NOTE: The # indicates the position.

1
  • 1
    Thanks for the correction, I speak a very bad English, but I try to improve and help a little :)
    – Skamasle
    Sep 18, 2013 at 22:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .