help with cache misses Apache2 mod.fcgid with Varnish 3

Mark Strickland dev at serviidbgroup.info
Wed Jun 12 00:18:00 CEST 2013


I am running Apache2 mod.fcgid with Varnish 3 as a cache.  I am getting
around 50% cache misses.   I would appreciate any help or hints on what I am
doing wrong with my default.vcl.  

 

cid:image001.png at 01CE654D.EC949250

 

Here is my default.vcl 

 

 

# This is a basic VCL configuration file for varnish.  See the vcl(7)

# man page for details on VCL syntax and semantics.

#

 

# TODO: Update internal subnet ACL and security.

 

# Define the internal network subnet.

# These are used below to allow internal access to certain files while not

# allowing access from the public internet.

# acl internal {

#  "192.10.0.0"/24;

# }

 

# Default backend definition.  Set this to point to your content

# server.

#

backend default {

.host = "127.0.0.1";

.port = "8080";

.connect_timeout = 600s;

.first_byte_timeout = 600s;

.between_bytes_timeout = 600s;

.max_connections = 800;

}

 

acl purge {

  "localhost";

  "127.0.0.1";

}

 

 

# Respond to incoming requests.

sub vcl_recv {

                # Use anonymous, cached pages if all backends are down.

  if (!req.backend.healthy) {

    unset req.http.Cookie;

  }

  

  # Allow the backend to serve up stale content if it is responding slowly.

  set req.grace = 6h;

                

  if (req.restarts == 0) {

  if (req.http.X-Forwarded-For) {

    set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " +
client.ip;

  } else {

    set req.http.X-Forwarded-For = client.ip;

  }

}

   

# Check the incoming request type is "PURGE", not "GET" or "POST"

if (req.request == "PURGE") {

  # Check if the ip coresponds with the acl purge

  if (!client.ip ~ purge) {

  # Return error code 405 (Forbidden) when not

    error 405 "Not allowed.";

  }

  return (lookup);

}

   

  # Pipe these paths directly to Apache for streaming.

  #if (req.url ~ "^/admin/content/backup_migrate/export") {

  #  return (pipe);

  #}

  #req.url ~ "^.*/api/.*$" ||

  # Do not cache these paths.

  if (req.url ~ "^/status\.php$" ||

                 req.url ~ "^/update\.php$" ||

                req.url ~ "^/admin$" ||

                req.url ~ "^/admin/.*$" ||

req.url ~ "^.*/apidev/.*$" ||

                req.url ~ "^/flag/.*$" ||

                req.url ~ "^.*/munin/.*$" ||

                  req.url ~ "^.*/server-status/.*$" ||

                  req.url ~ "^.*/store_us/.*$" ||

                  req.url ~ "^.*/store_us_test/.*$" ||

                  req.url ~ "^.*/store_ca/.*$" ||

                  req.url ~ "^.*/store_uk/.*$" ||

                  req.url ~ "^.*/store_de/.*$" ||

                  req.url ~ "^.*/store_fr/.*$" ||

                  req.url ~ "^.*/store_it/.*$" ||

                  req.url ~ "^.*/store_cn/.*$" ||

                  req.url ~ "^.*/store_es/.*$" ||

                  req.url ~ "^.*/store_jp/.*$" ||

                 req.url ~ "^.*/ajax/.*$" ||

                  req.url ~ "^.*/dev.serviidb.com/.*$" ||

                  req.url ~ "^.*/user/.*$" ||

                  req.url ~ "^.*/cacti/.*$" ||

                  req.url ~ "^.*/admin/.*$" ||

                  req.url ~ "^.*/install/.*$" ||

                  req.url ~ "^.*/serviioweb/.*$" ||

                 req.url ~ "^.*/mediabrowser/.*$" ||

                 req.url ~ "^.*/phpmyadmin/.*$" ||

                  req.url ~ "^.*/xataface/.*$") {

       return (pass);

  }

 

  # Do not allow outside access to cron.php or install.php.

  #if (req.url ~ "^/(cron|install)\.php$" && !client.ip ~ internal) {

    # Have Varnish throw the error directly.

  #  error 404 "Page not found.";

    # Use a custom error page that you've defined in Drupal at the path
"404".

    # set req.url = "/404";

  #}

 

  # Always cache the following file types for all users. This list of
extensions

  # appears twice, once here and again in vcl_fetch so make sure you edit
both

  # and keep them equal.

  if (req.url ~
"(?i)\.(pdf|asc|dat|txt|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|css|js)
(\?.*)?$") {

    unset req.http.Cookie;

  }

 

 # Remove all cookies that Drupal doesn't need to know about. We explicitly 

  # list the ones that Drupal does need, the SESS and NO_CACHE. If, after 

  # running this code we find that either of these two cookies remains, we 

  # will pass as the page cannot be cached.

  if (req.http.Cookie) {

    # 1. Append a semi-colon to the front of the cookie string.

    # 2. Remove all spaces that appear after semi-colons.

    # 3. Match the cookies we want to keep, adding the space we removed 

    #    previously back. (\1) is first matching group in the regsuball.

    # 4. Remove all other cookies, identifying them by the fact that they
have

    #    no space after the preceding semi-colon.

    # 5. Remove all spaces and semi-colons from the beginning and end of the


    #    cookie string. 

    set req.http.Cookie = ";" + req.http.Cookie;

    set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");    

    set req.http.Cookie = regsuball(req.http.Cookie,
";(SESS[a-z0-9]+|SSESS[a-z0-9]+|NO_CACHE)=", "; \1=");

    set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");

    set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");

 

    if (req.http.Cookie == "") {

      # If there are no remaining cookies, remove the cookie header. If
there

      # aren't any cookie headers, Varnish's default behavior will be to
cache

      # the page.

      unset req.http.Cookie;

    }

    else {

      # If there is any cookies left (a session or NO_CACHE cookie), do not

      # cache the page. Pass it on to Apache directly.

      return (pass);

    }

  }

 

}

 

# Set a header to track a cache HIT/MISS.

sub vcl_deliver {

  if (obj.hits > 0) {

    set resp.http.X-Varnish-Cache = "HIT";

  }

  else {

    set resp.http.X-Varnish-Cache = "MISS";

  }

}

 

# Code determining what to do when serving items from the Apache servers.

# beresp == Back-end response from the web server.

sub vcl_fetch {

  # We need this to cache 404s, 301s, 500s. Otherwise, depending on backend
but 

  # definitely in Drupal's case these responses are not cacheable by
default.

  if (beresp.status == 404 || beresp.status == 301 || beresp.status == 500)
{

    set beresp.ttl = 10m;

  }

  # this section of code sets the API to return a response code of 200 not
302.  DO NOT MODIFY OR DELETE COULD MESS UP CLIENTS.

    if(beresp.status == 302 && !beresp.http.Location){

    set beresp.status = 200; 

    set beresp.response = "OK";

  }

 

  # Don't allow static files to set cookies. 

  # (?i) denotes case insensitive in PCRE (perl compatible regular
expressions).

  # This list of extensions appears twice, once here and again in vcl_recv
so 

  # make sure you edit both and keep them equal.

  if (req.url ~
"(?i)\.(pdf|asc|dat|txt|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|css|js)
(\?.*)?$") {

    unset beresp.http.set-cookie;

  }

 

  # Allow items to be stale if needed.

  set beresp.grace = 6h;

}

 

sub vcl_hit {

        if (req.request == "PURGE") {

                purge;

                error 200 "Purged.";

        }

}

 

sub vcl_miss {

        if (req.request == "PURGE") {

                purge;

                error 200 "Purged.";

        }

}

 

# In the event of an error, show friendlier messages.

sub vcl_error {

  # Redirect to some other URL in the case of a homepage failure.

  #if (req.url ~ "^/?$") {

  #  set obj.status = 302;

  #  set obj.http.Location = "http://backup.example.com/";

  #}

 

  # Otherwise redirect to the homepage, which will likely be in the cache.

  set obj.http.Content-Type = "text/html; charset=utf-8";

  synthetic {"

<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 "} + obj.status + " " + obj.response +
{")</div>

  </div>

</body>

</html>

"};

  return (deliver);

}

 

 

Requests.log

 

/ hit

/ hit

/api/media.json?client=ServiiDroid&num=0 miss

/api/plugin.json?client=ServiiDroid&num=0 miss

/sites/default/files/hulu.png miss

/sites/default/files/comedycentral.jpg miss

/sites/default/files/CBS_0.jpg miss

/sites/default/files/abc_iview.jpg miss

/sites/default/files/4OD-logo.jpg miss

/ hit

/ hit

/sl/taxonomy/term/116/all miss

/ hit

/ru/node/317?language=de miss

/ hit

/ hit

/ hit

/sl/taxonomy/term/130/all miss

/plugin-api-name/youtubetop100 miss

/ hit

/ hit

/da/content/abc-iview-australia?language=en miss

/ hit

/sl/taxonomy/term/130/all miss

/ru/content/haha-sport-baseball?language=de miss

/ hit

/ hit

/ hit

/?q=node/add miss

/plugin-api-name/youtubetop100 miss

/node/add miss

/ hit

/user/register miss

/user/register miss

/ hit

/ja/comment/7?language=ja miss

/sites/default/files/itv.jpg miss

/sites/default/files/syfy.jpg miss

/sl/taxonomy/term/130/all miss

/sites/default/files/coco.jpg miss

/sites/default/files/css/css_fUXc0IbfJFVGhZ_CC63oYAw5rSt49epRhzcGmscaISU.css
hit

/sites/default/files/css/css_SKdZ0BB5XafXDbZJFEkdKM2wno6BIT2kaNm5ZvTeTgA.css
miss

/sites/default/files/css/css_KhS183x7gviqG0CuFRJJAOmVB1hHNwf9ofpIxQ9WMmE.css
hit

/sites/default/files/eclp_3.png hit

/sites/all/modules/addtoany/images/share_save_171_16.png hit

/sites/default/files/css/css_5_EBsvYf_U3gqgv1Idal1sImw7zcXB1kaIR6NOugp8o.css
hit

/sites/default/files/bbciplayer.png miss

/misc/feed.png hit

/sites/default/files/castalba.jpg miss

/sites/default/files/skysportsplus.png miss

/sites/default/files/hahasport.png miss

/sites/default/files/coolsporttv.png miss

/ hit

/ hit

/sites/default/files/sopcast.jpg miss

/sites/default/files/stopstream_0.png miss

/ar/ar/content/data/view/api_access?client_op=contains&client=&page=16 miss

/sites/default/files/dailymotion.jpg miss

/sites/default/files/twitch.png miss

/sites/default/files/Ustream.jpg miss

/sites/default/files/vimeo.jpg miss

/sites/default/files/YouTube.jpg miss

/sites/default/files/canalplus.jpg miss

/sites/default/files/m6groupe.png miss

/plugin-api-name/youtubetop100 miss

/ hit

/ hit

/zh-hans/node/199?language=en miss

/zh-hans/node/863?language=en miss

/api/install?client=ServiiDroid&nid=175.0 miss

/ hit

/sl/content/pilgrims-death miss

/content/how-cook-heston?language=ru miss

/ hit

/plugin-api-name/youtubetop100 miss

/sl/node/239 miss

/da/edit-plugin miss

/ hit

/ hit

/ hit

/plugin-api-name/youtubetop100 miss

/api/install?client=ServiiDroid&nid=771.0 miss

/ hit

/ hit

/ hit

/es/media-type/video?language=en miss

/es/media-type/video?language=en miss

/ hit

/plugin-api-name/youtubetop100 miss

/unpublished-forum miss

/ hit

/robots.txt hit

/ hit

/unpublished-forum miss

/content/pokemon miss

/content/conan-celebrity-interviews?language=es miss

/sl/region/uk?language=en miss

/unpublished-forum miss

/batch?op=start&id=1516 miss

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130611/96b69a72/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 22305 bytes
Desc: not available
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130611/96b69a72/attachment-0001.png>


More information about the varnish-misc mailing list