Help with vcl file

Ian Macdonald ianmac51 at gmail.com
Sun Jul 10 09:25:42 CEST 2016


Hi All,

New to varnish and this is probably something silly, but I have been
looking and nothing jumps out.

The below config is just me playing and learning, it works with ubuntu
16.04 and varnish 4.1.1 but not on CentOS 7 with varnish 4.1.3, if I
request the / I do get a synth response, but if I request /index.html
I get my custom 503 page, index.html is on the backend and will load
if I use a basic config, any suggestions would be greatly appreciated.

Best regards

Mackyd

# Playing with Varnish 4
# need to tell varnish what version the vcl is for
vcl 4.0;
# don't forget if you need a module function you need to import it
import std;
import vsthrottle;
import tcp;

backend default {
  .host = "192.168.1.71";
  .port = "8081";
  .max_connections = 3;
}

sub vcl_recv {
        # Strip any request cookies
        unset req.http.cookie;

# this could be of use for testing sends tcp data to log file
tcp.dump_info();
# Just playing with throttle here, practice modules usage
# This works for client ip as expected.
if (vsthrottle.is_denied(client.ip, 15, 10s)) {
                # Client has exceeded 15 reqs per 10s
                return (synth(429, "Too Many Requests"));
        }

        # respond HTTP 200 to / requests
        # LB Health check
        if (req.url ~ "^/$") {
return (synth(750));
        }

if (req.url ~ "^/none.html$") {
return (synth(760));
}

        # Make sure the LB Health check is passed through
        # to backend
        if (req.url ~ "^/search\?q=chutney$") {
                return (pass);
        }

# backend pass through to test max_connections

if (req.url ~ "^/bepass.html$") {
return (pass);
}


}

sub vcl_backend_response {
        if (bereq.url ~ "^/suggest\?") {
                set beresp.ttl = 360m;
        } else {
                set beresp.ttl = 2m;
        }
}

sub vcl_synth {
    if (resp.status == 750) {
set resp.status = 200;
# we probably don't need the synthetic here
# if the load balancer is only looking for
# status 200 but it is useful to know what
# is being sent
synthetic("Response to load balancer health probe");
return(deliver);
}

    if (resp.status == 760) {
set resp.status = 200;
synthetic(std.fileread("/etc/varnish/500.html"));
return(deliver);
}

}

sub vcl_backend_error {
    if (beresp.status == 503) {
set beresp.http.Content-Type = "text/html; charset=utf-8";
synthetic(std.fileread("/etc/varnish/500.html"));
    return (deliver);


    }

/* The 'else' does not seem to get called and the 404
 * is passed through from the backend, need to figure
 * out why at some point
 */


    else {
    set beresp.http.Content-Type = "text/html; charset=utf-8";
    synthetic( {"<!DOCTYPE html>
       <html>
         <head>
            <title>"} + beresp.status + " " + beresp.reason + {"</title>
         </head>
         <body>
           <h1>Error "} + beresp.status + " " + beresp.reason + {"</h1>
           <p>"} + beresp.reason + {"</p>
           <h3>Guru Meditation:</h3>
           <p>XID: "} + bereq.xid + {"</p>
           <hr>
           <p>Varnish cache server error from else section vcl_backend_error
           </p>
         </body>
       </html>
    "} );
    return (deliver);
   }

}



More information about the varnish-misc mailing list