Skip to content

Instantly share code, notes, and snippets.

@garlandkr
Created October 10, 2011 20:17
Show Gist options
  • Save garlandkr/1276390 to your computer and use it in GitHub Desktop.
Save garlandkr/1276390 to your computer and use it in GitHub Desktop.
Varnish 3.0 syntax issue
sub vcl_error {
# CUSTOM
# -- Redirect the url when received from mobile device -- control transfered from vcl_request (see above)
if (obj.status == 750) {
set obj.http.Location = "http://mobile.blah.com";
set obj.status = 301;
return(deliver);
}
# -- Restart unless max_restarts is reached
if (obj.status == 503 && req.restarts < 4) {
return(restart);
}
# -- Set 500 Error page. Cribbed from http://mohanjith.net/blog/2009/08/using-custom-error-pages-in-varnish.html
if ( (obj.status >= 500 && obj.status <= 505) ) {
set obj.http.Content-Type = "text/html; charset=utf-8";
C{
FILE * pFile;
char content [100];
char page [10240];
char fname [50];
page[0] = '\0';
sprintf(fname, "/var/www/errors/%d.html", VRT_r_obj_status(sp));
pFile = fopen(fname, "r");
while (fgets(content, 100, pFile)) {
strcat(page, content);
}
fclose(pFile);
VRT_synth_page(sp, 0, page, "<!-- XID: ", VRT_r_req_xid(sp), " -->", vrt_magic_string_end);
}C
} else {
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>
</head>
<body>
<h1>Error “} + obj.status + ” ” + obj.response + {“</h1>
<p>”} + obj.response + {“</p>
<h3>Guru Meditation:</h3>
<p>XID: “} + req.xid + {“</p>
<hr>
<p>Varnish cache server</p>
</body>
</html>
"};
}
return (deliver);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment