Skip to content

Instantly share code, notes, and snippets.

@darkhelmet
Forked from adamwiggins/heroku.vcl
Created October 29, 2010 20:21

Revisions

  1. adamwiggins created this gist Oct 29, 2010.
    60 changes: 60 additions & 0 deletions heroku.vcl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    director routing_mesh round-robin {
    {
    .backend = {
    .host = "...some ip...";
    .port = "...some port...";
    .first_byte_timeout = 90s;
    .between_bytes_timeout = 90s;
    }
    # ...more backends...
    }
    }

    sub vcl_recv {
    set req.backend = routing_mesh;

    # POST, PUT, and DELETE are not cached
    if (req.request != "GET" && req.request != "HEAD") {
    return (pass);
    }

    # never cache when http basic auth is used
    if (req.http.Authorization) {
    return (pass);
    }

    # serve stale items for 30 seconds while fetching new item from backend
    set req.grace = 30s;

    return (lookup);
    }

    sub vcl_fetch {
    # cache 200s set to cache public
    if (obj.cacheable && obj.http.Cache-Control ~ "public") {
    set obj.prefetch = -30s;
    unset obj.http.set-cookie;
    return (deliver);
    }

    # everything else is served dynamically
    return (pass);
    }


    sub vcl_error {
    set obj.http.Content-Type = "text/html; charset=utf-8";
    synthetic {"...error page html..."};
    return (deliver);
    }

    # Disable keep-alive support with backends
    sub vcl_miss {
    set bereq.http.Connection = "close";
    }
    sub vcl_pass {
    set bereq.http.Connection = "close";
    }
    sub vcl_pipe {
    set bereq.http.Connection = "close";
    }