[Varnish] #919: 503 error from varish while apache returns 200

Varnish varnish-bugs at varnish-cache.org
Wed May 18 11:32:12 CEST 2011


#919: 503 error from varish while apache returns 200
------------------------+---------------------------------------------------
 Reporter:  damol       |        Type:  defect
   Status:  new         |    Priority:  normal
Milestone:              |   Component:  build 
  Version:  trunk       |    Severity:  normal
 Keywords:  503 centos  |  
------------------------+---------------------------------------------------
 in one of 10000 requests i am recieving an 503 error. with mostly this
 rule in my varnishlog:
 {{{
 30 FetchError   c http read error: 11
 }}}
 my varnish.vcl:

 {{{
 # This is the configuration of varnish this file contains several checks
 that decides to cache a page or not.
 # Author: Daan Molenaar
 C{
                 #include <stdio.h>
                 #include <stdlib.h>
                 #include <string.h>
 }C
 # first we tell how we can talk to the default webserver
 backend default {
         .host = "127.0.0.1";
         .port = "8080";
         .connect_timeout = 600s;
         .first_byte_timeout = 600s;
         .between_bytes_timeout = 600s;
 }

 sub vcl_recv {
         ## check the custom configuration file if the url is allowed to be
 handled by varnish
         C{
                 FILE * pFile;
                 long lSize;
                 char * buffer;
                 size_t result;

                 pFile = fopen ( "/etc/varnish/websites.cfg" , "rb" );
                 if (pFile==NULL) {fputs ("File error",stderr); exit (1);}

                 // obtain file size:
                 fseek (pFile , 0 , SEEK_END);
                 lSize = ftell (pFile);
                 rewind (pFile);

                 // allocate memory to contain the whole file:
                 buffer = (char*) malloc (sizeof(char)*lSize);
                 if (buffer == NULL) {fputs ("Memory error",stderr); exit
 (2);}

                 // copy the file into the buffer:
                 result = fread (buffer,1,lSize,pFile);
                 if (result != lSize) {fputs ("Reading error",stderr); exit
 (3);}

                 /* the whole file is now loaded in the memory buffer. */
                 char *host = VRT_GetHdr(sp, HDR_REQ, "\005Host:");
                 char * pch;
                 // add a < and > to be sure you get the complete host
                 char new_host[80];
                 strcpy (new_host,"<");
                 strcat (new_host,host);
                 strcat (new_host,">");
                 pch = strstr (buffer, new_host);
                 if(pch){
                         VRT_SetHdr(sp, HDR_REQ, "\014X-May-Cache:", "YES",
 vrt_magic_string_end);
                 }
                 // terminate
                 fclose (pFile);
                 free (buffer);
         }C

         # if caching for this website is not enabled
         if (req.http.X-May-Cache !~ "YES") {
                 return(pass);
         }
     ## Default request checks
     if (req.request != "GET" &&
         req.request != "HEAD" &&
         req.request != "PUT" &&
         req.request != "POST" &&
         req.request != "TRACE" &&
         req.request != "OPTIONS" &&
         req.request != "DELETE") {
             # Non-RFC2616 or CONNECT which is weird.
             return (pipe);
     }
     if (req.request != "GET" && req.request != "HEAD") {
         # We only deal with GET and HEAD by default
         return (pass);
     }

         ## Remove has_js and Google Analytics cookies.
         set req.http.Cookie = regsuball(req.http.Cookie,
 "(^|;\s*)(__[a-z]+)=[^;]*", "");

         ## set the browser to IE because the content does not differ
     set req.http.user-agent = "MSIE";


         ## Remove a ";" prefix, if present.
         set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
         ## Remove empty cookies.
         if (req.http.Cookie ~ "^\s*$") {
                 unset req.http.Cookie;
         }
         ## Let's have a little grace
         set req.grace = 60s;

         ## Normalize the Accept-Encoding header
         ## as per: http://varnish-cache.org/wiki/FAQ/Compression
         if (req.http.Accept-Encoding) {
                 if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$" ||
 req.url ~ "robots\.txt") {
                         # No point in compressing these
                         remove req.http.Accept-Encoding;
                 } elsif (req.http.Accept-Encoding ~ "gzip") {
                         set req.http.Accept-Encoding = "gzip";
                 } elsif (req.http.Accept-Encoding ~ "deflate") {
                         set req.http.Accept-Encoding = "deflate";
                 } else {
                         # unkown encoding algorithm
                         remove req.http.Accept-Encoding;
                 }
         }
         ## cache css js and images always also when no user is logged in
         if (req.url ~ "\.(css|js|jpg|jpeg|gif|ico|png)$") {
                 lookup;
         }

         ## No varnish for install,update.php or cron.php
         if (req.url ~ "install\.php|update\.php|cron\.php") {
                 return (pass);
         }


         if (req.http.Cookie ~ "NO_CACHE=Y") {
                 # there is no "no-cache" cookie set in the site
                 return (pass);
         }
         lookup;
 }
 sub vcl_fetch {
         // set the time to live to one hour
         set obj.ttl = 3600s;
         set obj.grace = 60s;
 }
 ### vcl_hash creates the key for varnish under which the object is stored.
 It is
 ### possible to store the same url under 2 different keys, by making
 vcl_hash
 ### create a different hash.
 sub vcl_hash {

     ## these 2 entries are the default ones used for vcl. Below we add our
 own.
     set req.hash += req.url;
     set req.hash += req.http.host;
     ## cache css js and images always
         #if(req.url !~ "\.(css|js|jpg|jpeg|gif|ico|png)$"){
                 ## Remove the SESSION cookie from the cookie and save it
 in the Hash
                 set req.http.X-SYNETIC-COOKIE-NO-SESS =
 regsuball(req.http.Cookie, "(^|; ) *SESS[A-Za-z0-9=]+;? *", "\1");
         set req.hash += req.http.X-SYNETIC-COOKIE-NO-SESS;
     #}
     hash;
 }


 sub vcl_error {
   // Let's deliver a slightly more friedly error page.
   // You can customize this as you wish.

   set obj.http.Content-Type = "text/html; charset=utf-8";
   synthetic {"
   <?xml version="1.0" encoding="utf-8"?>
   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   <html>
     <head>
       <title>"} obj.status " " obj.response {"</title>
       <style type="text/css">
       #page {width: 400px; padding: 10px; margin: 20px auto; border: 1px
 solid black; background-color: #FFF;}
       p {margin-left:20px;}
       body {background-color: #DDD; margin: auto;}
       </style>
     </head>
     <body>
                 <div id="page">
                 <h1>Page Could Not Be Loaded</h1>
                 <p>We're very sorry, but the page could not be loaded
 properly. This should be fixed very soon, and we apologize for any
 inconvenience.</p>
                 <hr />
                 <h4>Debug Info:</h4>
                 <pre>
                         Status: "} obj.status {"
                         Response: "} obj.response {"
                         XID: "} req.xid {"
                 </pre>
                 <address><a href="http://www.varnish-
 cache.org/">Varnish</a></address>
       </div>
     </body>
    </html>
    "};
    deliver;
 }

 sub vcl_deliver {
     return (deliver);
 }

 }}}


 i am running centos 5.5 64x

-- 
Ticket URL: <http://varnish-cache.org/trac/ticket/919>
Varnish <http://varnish-cache.org/>
The Varnish HTTP Accelerator




More information about the varnish-bugs mailing list