Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- backend default {
- .host = "127.0.0.1";
- .port = "8080";
- .connect_timeout = 600s;
- .first_byte_timeout = 600s;
- .between_bytes_timeout = 600s;
- }
- acl purge {
- "localhost";
- "127.0.0.1";
- "10.129.22.21";
- }
- acl allowservers {
- "10.129.22.21";
- }
- sub vcl_recv {
- if (req.request == "PURGE") {
- if (!client.ip ~ purge) {
- error 405 "Not allowed.";
- }
- purge("req.url ~ " req.url);
- }
- // Remove has_js and Google Analytics cookies.
- set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js)=[^;]*", "");
- // 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;
- }
- // No varnish for update.php, cron.php, xmlrpc.php
- if (req.url ~ "cron\.php|update\.php|xmlrpc\.php") {
- if (!client.ip ~ allowservers) {
- error 403 "Not allowed.";
- } else {
- return(pass);
- }
- }
- if (req.request == "GET" && req.url ~ "^/sites/") {
- // we only ever want to deal with GET requests, we are working
- // on the assumption that everything in sites is served the same
- // to all users so we don't want the cookie */
- unset req.http.cookie;
- #pass;
- return(lookup);
- }
- if (req.request == "GET" && req.url ~ "^/flash/") {
- #unset req.http.cookie;
- return(lookup);
- }
- if (req.request == "GET" && req.url ~ "^/files/") {
- unset req.http.cookie;
- return(lookup);
- }
- #if (req.request != "GET" && req.request != "HEAD") {
- # return(pipe);
- #}
- #if (req.http.Authenticate || req.http.Authorization) {
- # return(pipe);
- #}
- #if (req.http.Cookie && req.http.Cookie ~ "authtoken=") {
- # return(pipe);
- #}
- // 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)$") {
- # 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 algorithm
- remove req.http.Accept-Encoding;
- }
- }
- // Let's have a little grace
- set req.grace = 30s;
- }
- ### Strip any cookies before an image/js/css is inserted into cache.
- ### Also: future-support for ESI.
- sub vcl_fetch {
- if (beresp.status == 302 || beresp.status == 301) {
- return(pass);
- }
- if (req.request == "GET" && req.url ~ "^/sites/") {
- // we can unset the Cookie Drupal adds, set a lifetime for the object
- // and make it cacheable */
- unset beresp.http.Set-Cookie;
- set beresp.cacheable = true;
- # we can set how long Varnish will keep the object here, or later
- #set beresp.ttl = 30m;
- set beresp.ttl = 604800s;
- # debug add this and you'll see it in the headers if we came here
- #set beresp.http.X-Drupal-Varnish-Debug = "1";
- set beresp.http.X-Sites-Directory = "sites";
- }
- if (req.request == "GET" && req.url ~ "^/files/") {
- unset beresp.http.Set-Cookie;
- set beresp.cacheable = true;
- set beresp.ttl = 604800s;
- set beresp.http.X-Files-Directory = "files";
- }
- if (req.request == "GET" && req.url ~ "^/flash/") {
- unset beresp.http.Set-Cookie;
- set beresp.cacheable = true;
- set beresp.ttl = 604800s;
- set beresp.http.X-Varnish-FLASH = "flash!!!!";
- }
- if (beresp.cacheable) {
- // Things common to all cacheable objects, here it removes
- // the Expires that are often in the past, sets cache control
- // and how long varnish will keep it
- // and mark it for delivery (and storing) */
- set beresp.cacheable = true;
- unset beresp.http.expires;
- set beresp.http.cache-control = "max-age = 1900";
- set beresp.ttl = 1w;
- set beresp.http.magicmarker = "1";
- set beresp.http.cachable = "1";
- return(deliver);
- }
- if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
- unset beresp.http.set-cookie;
- set beresp.http.X-Files = "png|gif|jpg|swf|css|js";
- }
- esi;
- }
- sub vcl_hash {
- if (req.http.Cookie) {
- set req.hash += req.http.Cookie;
- }
- }
- sub vcl_deliver {
- if (resp.http.magicmarker) {
- /* unset marker and serve it for upstream as new */
- unset resp.http.magicmarker;
- set resp.http.age = "0";
- }
- }
- sub vcl_error {
- etc....
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement