Difference between revisions of "Varnish Configuration"
Jump to navigation
Jump to search
(Created page with "= Overview = = Example Configuration = # # This is an example VCL file for Varnish. # # See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | [[Category:How_To]] | ||
= Overview = | = Overview = | ||
− | |||
− | |||
= Example Configuration = | = Example Configuration = |
Latest revision as of 23:49, 10 September 2023
Overview
Example Configuration
# # This is an example VCL file for Varnish. # # See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/ # and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples. # Marker to tell the VCL compiler that this VCL has been adapted to the # new 4.0 format. vcl 4.0; # Default backend definition. Set this to point to your content server. backend default { .host = "127.0.0.1"; .port = "8060"; .first_byte_timeout = 600s; } sub vcl_recv { set req.backend_hint= default; # Allow PURGE from trusted sources if (req.method == "PURGE") { if (!client.ip ~ purge) { return(synth(405,"Not allowed.")); } return (purge); } # Allow BAN from trusted sources if (req.method == "BAN") { if (!client.ip ~ purge) { return(synth(403, "Not allowed.")); } # It may be necessary to state your URL rather than obtain it from req.http.host ban("req.http.host == " + req.http.host + " && req.url ~ " + req.url); #ban("req.http.host == myserver.org && req.url ~ " + req.url); # Throw a synthetic page so the # request won't go to the backend. return(synth(200, "Ban added")); } # Preserve language modifiers if (req.http.Accept-Language) { if (req.http.Accept-Language ~ "en") { set req.http.Accept-Language = "en"; } elsif (req.http.Accept-Language ~ "fr") { set req.http.Accept-Language = "fr"; } elsif (req.http.Accept-Language ~ "de") { set req.http.Accept-Language = "de"; } elsif (req.http.Accept-Language ~ "aa") { set req.http.Accept-Language = "aa"; } elsif (req.http.Accept-Language ~ "ab") { set req.http.Accept-Language = "ab"; } elsif (req.http.Accept-Language ~ "ae") { set req.http.Accept-Language = "ae"; } elsif (req.http.Accept-Language ~ "af") { set req.http.Accept-Language = "af"; } elsif (req.http.Accept-Language ~ "ak") { set req.http.Accept-Language = "ak"; } elsif (req.http.Accept-Language ~ "am") { set req.http.Accept-Language = "am"; } elsif (req.http.Accept-Language ~ "an") { set req.http.Accept-Language = "an"; } elsif (req.http.Accept-Language ~ "ar") { set req.http.Accept-Language = "ar"; } elsif (req.http.Accept-Language ~ "as") { set req.http.Accept-Language = "as"; } elsif (req.http.Accept-Language ~ "av") { set req.http.Accept-Language = "av"; } elsif (req.http.Accept-Language ~ "ay") { set req.http.Accept-Language = "ay"; } elsif (req.http.Accept-Language ~ "az") { set req.http.Accept-Language = "az"; } elsif (req.http.Accept-Language ~ "ba") { set req.http.Accept-Language = "ba"; } elsif (req.http.Accept-Language ~ "be") { set req.http.Accept-Language = "be"; } elsif (req.http.Accept-Language ~ "bg") { set req.http.Accept-Language = "bg"; } elsif (req.http.Accept-Language ~ "bh") { set req.http.Accept-Language = "bh"; } elsif (req.http.Accept-Language ~ "bi") { set req.http.Accept-Language = "bi"; } elsif (req.http.Accept-Language ~ "bm") { set req.http.Accept-Language = "bm"; } elsif (req.http.Accept-Language ~ "bn") { set req.http.Accept-Language = "bn"; } elsif (req.http.Accept-Language ~ "bo") { set req.http.Accept-Language = "bo"; } elsif (req.http.Accept-Language ~ "br") { set req.http.Accept-Language = "br"; } elsif (req.http.Accept-Language ~ "bs") { set req.http.Accept-Language = "bs"; } elsif (req.http.Accept-Language ~ "ce") { set req.http.Accept-Language = "ce"; } elsif (req.http.Accept-Language ~ "ch") { set req.http.Accept-Language = "ch"; } elsif (req.http.Accept-Language ~ "co") { set req.http.Accept-Language = "co"; } elsif (req.http.Accept-Language ~ "cr") { set req.http.Accept-Language = "cr"; } elsif (req.http.Accept-Language ~ "cs") { set req.http.Accept-Language = "cs"; } elsif (req.http.Accept-Language ~ "cu") { set req.http.Accept-Language = "cu"; } elsif (req.http.Accept-Language ~ "cv") { set req.http.Accept-Language = "cv"; } elsif (req.http.Accept-Language ~ "cy") { set req.http.Accept-Language = "cy"; } elsif (req.http.Accept-Language ~ "da") { set req.http.Accept-Language = "da"; } elsif (req.http.Accept-Language ~ "dv") { set req.http.Accept-Language = "dv"; } elsif (req.http.Accept-Language ~ "dz") { set req.http.Accept-Language = "dz"; } elsif (req.http.Accept-Language ~ "ee") { set req.http.Accept-Language = "ee"; } elsif (req.http.Accept-Language ~ "el") { set req.http.Accept-Language = "el"; } elsif (req.http.Accept-Language ~ "eo") { set req.http.Accept-Language = "eo"; } elsif (req.http.Accept-Language ~ "es") { set req.http.Accept-Language = "es"; } elsif (req.http.Accept-Language ~ "et") { set req.http.Accept-Language = "et"; } elsif (req.http.Accept-Language ~ "eu") { set req.http.Accept-Language = "eu"; } elsif (req.http.Accept-Language ~ "fa") { set req.http.Accept-Language = "fa"; } elsif (req.http.Accept-Language ~ "ff") { set req.http.Accept-Language = "ff"; } elsif (req.http.Accept-Language ~ "fi") { set req.http.Accept-Language = "fi"; } elsif (req.http.Accept-Language ~ "fj") { set req.http.Accept-Language = "fj"; } elsif (req.http.Accept-Language ~ "fo") { set req.http.Accept-Language = "fo"; } elsif (req.http.Accept-Language ~ "fy") { set req.http.Accept-Language = "fy"; } elsif (req.http.Accept-Language ~ "ga") { set req.http.Accept-Language = "ga"; } elsif (req.http.Accept-Language ~ "gd") { set req.http.Accept-Language = "gd"; } elsif (req.http.Accept-Language ~ "gl") { set req.http.Accept-Language = "gl"; } elsif (req.http.Accept-Language ~ "gn") { set req.http.Accept-Language = "gn"; } elsif (req.http.Accept-Language ~ "gu") { set req.http.Accept-Language = "gu"; } elsif (req.http.Accept-Language ~ "gv") { set req.http.Accept-Language = "gv"; } elsif (req.http.Accept-Language ~ "ha") { set req.http.Accept-Language = "ha"; } elsif (req.http.Accept-Language ~ "he") { set req.http.Accept-Language = "he"; } elsif (req.http.Accept-Language ~ "hi") { set req.http.Accept-Language = "hi"; } elsif (req.http.Accept-Language ~ "ho") { set req.http.Accept-Language = "ho"; } elsif (req.http.Accept-Language ~ "hr") { set req.http.Accept-Language = "hr"; } elsif (req.http.Accept-Language ~ "ht") { set req.http.Accept-Language = "ht"; } elsif (req.http.Accept-Language ~ "hu") { set req.http.Accept-Language = "hu"; } elsif (req.http.Accept-Language ~ "hy") { set req.http.Accept-Language = "hy"; } elsif (req.http.Accept-Language ~ "hz") { set req.http.Accept-Language = "hz"; } elsif (req.http.Accept-Language ~ "ia") { set req.http.Accept-Language = "ia"; } elsif (req.http.Accept-Language ~ "id") { set req.http.Accept-Language = "id"; } elsif (req.http.Accept-Language ~ "ie") { set req.http.Accept-Language = "ie"; } elsif (req.http.Accept-Language ~ "ig") { set req.http.Accept-Language = "ig"; } elsif (req.http.Accept-Language ~ "ii") { set req.http.Accept-Language = "ii"; } elsif (req.http.Accept-Language ~ "ik") { set req.http.Accept-Language = "ik"; } elsif (req.http.Accept-Language ~ "io") { set req.http.Accept-Language = "io"; } elsif (req.http.Accept-Language ~ "is") { set req.http.Accept-Language = "is"; } elsif (req.http.Accept-Language ~ "it") { set req.http.Accept-Language = "it"; } elsif (req.http.Accept-Language ~ "iu") { set req.http.Accept-Language = "iu"; } elsif (req.http.Accept-Language ~ "ja") { set req.http.Accept-Language = "ja"; } elsif (req.http.Accept-Language ~ "jv") { set req.http.Accept-Language = "jv"; } elsif (req.http.Accept-Language ~ "ka") { set req.http.Accept-Language = "ka"; } elsif (req.http.Accept-Language ~ "kg") { set req.http.Accept-Language = "kg"; } elsif (req.http.Accept-Language ~ "ki") { set req.http.Accept-Language = "ki"; } elsif (req.http.Accept-Language ~ "kj") { set req.http.Accept-Language = "kj"; } elsif (req.http.Accept-Language ~ "kk") { set req.http.Accept-Language = "kk"; } elsif (req.http.Accept-Language ~ "kl") { set req.http.Accept-Language = "kl"; } elsif (req.http.Accept-Language ~ "km") { set req.http.Accept-Language = "km"; } elsif (req.http.Accept-Language ~ "kn") { set req.http.Accept-Language = "kn"; } elsif (req.http.Accept-Language ~ "ko") { set req.http.Accept-Language = "ko"; } elsif (req.http.Accept-Language ~ "kr") { set req.http.Accept-Language = "kr"; } elsif (req.http.Accept-Language ~ "ks") { set req.http.Accept-Language = "ks"; } elsif (req.http.Accept-Language ~ "ku") { set req.http.Accept-Language = "ku"; } elsif (req.http.Accept-Language ~ "kv") { set req.http.Accept-Language = "kv"; } elsif (req.http.Accept-Language ~ "kw") { set req.http.Accept-Language = "kw"; } elsif (req.http.Accept-Language ~ "ky") { set req.http.Accept-Language = "ky"; } elsif (req.http.Accept-Language ~ "la") { set req.http.Accept-Language = "la"; } elsif (req.http.Accept-Language ~ "lb") { set req.http.Accept-Language = "lb"; } elsif (req.http.Accept-Language ~ "lg") { set req.http.Accept-Language = "lg"; } elsif (req.http.Accept-Language ~ "li") { set req.http.Accept-Language = "li"; } elsif (req.http.Accept-Language ~ "ln") { set req.http.Accept-Language = "ln"; } elsif (req.http.Accept-Language ~ "lo") { set req.http.Accept-Language = "lo"; } elsif (req.http.Accept-Language ~ "lt") { set req.http.Accept-Language = "lt"; } elsif (req.http.Accept-Language ~ "lu") { set req.http.Accept-Language = "lu"; } elsif (req.http.Accept-Language ~ "lv") { set req.http.Accept-Language = "lv"; } elsif (req.http.Accept-Language ~ "mg") { set req.http.Accept-Language = "mg"; } elsif (req.http.Accept-Language ~ "mh") { set req.http.Accept-Language = "mh"; } elsif (req.http.Accept-Language ~ "mi") { set req.http.Accept-Language = "mi"; } elsif (req.http.Accept-Language ~ "mk") { set req.http.Accept-Language = "mk"; } elsif (req.http.Accept-Language ~ "ml") { set req.http.Accept-Language = "ml"; } elsif (req.http.Accept-Language ~ "mn") { set req.http.Accept-Language = "mn"; } elsif (req.http.Accept-Language ~ "mr") { set req.http.Accept-Language = "mr"; } elsif (req.http.Accept-Language ~ "ms") { set req.http.Accept-Language = "ms"; } elsif (req.http.Accept-Language ~ "mt") { set req.http.Accept-Language = "mt"; } elsif (req.http.Accept-Language ~ "my") { set req.http.Accept-Language = "my"; } elsif (req.http.Accept-Language ~ "na") { set req.http.Accept-Language = "na"; } elsif (req.http.Accept-Language ~ "nb") { set req.http.Accept-Language = "nb"; } elsif (req.http.Accept-Language ~ "nd") { set req.http.Accept-Language = "nd"; } elsif (req.http.Accept-Language ~ "ne") { set req.http.Accept-Language = "ne"; } elsif (req.http.Accept-Language ~ "ng") { set req.http.Accept-Language = "ng"; } elsif (req.http.Accept-Language ~ "nl") { set req.http.Accept-Language = "nl"; } elsif (req.http.Accept-Language ~ "nn") { set req.http.Accept-Language = "nn"; } elsif (req.http.Accept-Language ~ "no") { set req.http.Accept-Language = "no"; } elsif (req.http.Accept-Language ~ "nr") { set req.http.Accept-Language = "nr"; } elsif (req.http.Accept-Language ~ "nv") { set req.http.Accept-Language = "nv"; } elsif (req.http.Accept-Language ~ "ny") { set req.http.Accept-Language = "ny"; } elsif (req.http.Accept-Language ~ "oc") { set req.http.Accept-Language = "oc"; } elsif (req.http.Accept-Language ~ "oj") { set req.http.Accept-Language = "oj"; } elsif (req.http.Accept-Language ~ "om") { set req.http.Accept-Language = "om"; } elsif (req.http.Accept-Language ~ "or") { set req.http.Accept-Language = "or"; } elsif (req.http.Accept-Language ~ "os") { set req.http.Accept-Language = "os"; } elsif (req.http.Accept-Language ~ "pa") { set req.http.Accept-Language = "pa"; } elsif (req.http.Accept-Language ~ "pi") { set req.http.Accept-Language = "pi"; } elsif (req.http.Accept-Language ~ "pl") { set req.http.Accept-Language = "pl"; } elsif (req.http.Accept-Language ~ "ps") { set req.http.Accept-Language = "ps"; } elsif (req.http.Accept-Language ~ "pt") { set req.http.Accept-Language = "pt"; } elsif (req.http.Accept-Language ~ "qu") { set req.http.Accept-Language = "qu"; } elsif (req.http.Accept-Language ~ "rm") { set req.http.Accept-Language = "rm"; } elsif (req.http.Accept-Language ~ "rn") { set req.http.Accept-Language = "rn"; } elsif (req.http.Accept-Language ~ "ro") { set req.http.Accept-Language = "ro"; } elsif (req.http.Accept-Language ~ "ru") { set req.http.Accept-Language = "ru"; } elsif (req.http.Accept-Language ~ "rw") { set req.http.Accept-Language = "rw"; } elsif (req.http.Accept-Language ~ "sa") { set req.http.Accept-Language = "sa"; } elsif (req.http.Accept-Language ~ "sc") { set req.http.Accept-Language = "sc"; } elsif (req.http.Accept-Language ~ "sd") { set req.http.Accept-Language = "sd"; } elsif (req.http.Accept-Language ~ "se") { set req.http.Accept-Language = "se"; } elsif (req.http.Accept-Language ~ "sg") { set req.http.Accept-Language = "sg"; } elsif (req.http.Accept-Language ~ "si") { set req.http.Accept-Language = "si"; } elsif (req.http.Accept-Language ~ "sk") { set req.http.Accept-Language = "sk"; } elsif (req.http.Accept-Language ~ "sl") { set req.http.Accept-Language = "sl"; } elsif (req.http.Accept-Language ~ "sm") { set req.http.Accept-Language = "sm"; } elsif (req.http.Accept-Language ~ "sn") { set req.http.Accept-Language = "sn"; } elsif (req.http.Accept-Language ~ "so") { set req.http.Accept-Language = "so"; } elsif (req.http.Accept-Language ~ "sq") { set req.http.Accept-Language = "sq"; } elsif (req.http.Accept-Language ~ "sr") { set req.http.Accept-Language = "sr"; } elsif (req.http.Accept-Language ~ "ss") { set req.http.Accept-Language = "ss"; } elsif (req.http.Accept-Language ~ "st") { set req.http.Accept-Language = "st"; } elsif (req.http.Accept-Language ~ "su") { set req.http.Accept-Language = "su"; } elsif (req.http.Accept-Language ~ "sv") { set req.http.Accept-Language = "sv"; } elsif (req.http.Accept-Language ~ "sw") { set req.http.Accept-Language = "sw"; } elsif (req.http.Accept-Language ~ "ta") { set req.http.Accept-Language = "ta"; } elsif (req.http.Accept-Language ~ "te") { set req.http.Accept-Language = "te"; } elsif (req.http.Accept-Language ~ "tg") { set req.http.Accept-Language = "tg"; } elsif (req.http.Accept-Language ~ "th") { set req.http.Accept-Language = "th"; } elsif (req.http.Accept-Language ~ "ti") { set req.http.Accept-Language = "ti"; } elsif (req.http.Accept-Language ~ "tk") { set req.http.Accept-Language = "tk"; } elsif (req.http.Accept-Language ~ "tl") { set req.http.Accept-Language = "tl"; } elsif (req.http.Accept-Language ~ "tn") { set req.http.Accept-Language = "tn"; } elsif (req.http.Accept-Language ~ "to") { set req.http.Accept-Language = "to"; } elsif (req.http.Accept-Language ~ "tr") { set req.http.Accept-Language = "tr"; } elsif (req.http.Accept-Language ~ "ts") { set req.http.Accept-Language = "ts"; } elsif (req.http.Accept-Language ~ "tt") { set req.http.Accept-Language = "tt"; } elsif (req.http.Accept-Language ~ "tw") { set req.http.Accept-Language = "tw"; } elsif (req.http.Accept-Language ~ "ty") { set req.http.Accept-Language = "ty"; } elsif (req.http.Accept-Language ~ "ug") { set req.http.Accept-Language = "ug"; } elsif (req.http.Accept-Language ~ "uk") { set req.http.Accept-Language = "uk"; } elsif (req.http.Accept-Language ~ "ur") { set req.http.Accept-Language = "ur"; } elsif (req.http.Accept-Language ~ "uz") { set req.http.Accept-Language = "uz"; } elsif (req.http.Accept-Language ~ "ve") { set req.http.Accept-Language = "ve"; } elsif (req.http.Accept-Language ~ "vi") { set req.http.Accept-Language = "vi"; } elsif (req.http.Accept-Language ~ "vo") { set req.http.Accept-Language = "vo"; } elsif (req.http.Accept-Language ~ "wa") { set req.http.Accept-Language = "wa"; } elsif (req.http.Accept-Language ~ "wo") { set req.http.Accept-Language = "wo"; } elsif (req.http.Accept-Language ~ "xh") { set req.http.Accept-Language = "xh"; } elsif (req.http.Accept-Language ~ "yi") { set req.http.Accept-Language = "yi"; } elsif (req.http.Accept-Language ~ "yo") { set req.http.Accept-Language = "yo"; } elsif (req.http.Accept-Language ~ "za") { set req.http.Accept-Language = "za"; } elsif (req.http.Accept-Language ~ "zh") { set req.http.Accept-Language = "zh"; } elsif (req.http.Accept-Language ~ "zu") { set req.http.Accept-Language = "zu"; } else { # unknown language. Remove the accept-language header and # use the backend default. unset req.http.Accept-Language; } } if (req.url ~ "/ws/public/sdmxapi/rest/data/") { # Destroy the COOKIE unset req.http.cookie; } else { return (pass); } } sub vcl_backend_response { # Happens after we have read the response headers from the backend. # # Here you clean the response headers, removing silly Set-Cookie headers # and other mistakes your backend does.
if (bereq.url ~ "/ws/public/sdmxapi/rest/data/") { # Destroy the COOKIE unset beresp.http.set-cookie; } } sub vcl_deliver { # Happens when we have all the pieces we need, and are about to send the # response to the client. # # You can do accounting or modifying the final object here. } sub vcl_backend_response { set beresp.ttl = 60m; } acl purge { # Specify the sites that you wish to be able to perform BANs "localhost"; "212.58.246.0"/24; }