Last active
March 5, 2020 08:40
-
-
Save chluehr/3188325 to your computer and use it in GitHub Desktop.
Pimore Varnish Default Configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is a basic VCL configuration file for varnish. See the vcl(7) | |
| # man page for details on VCL syntax and semantics. | |
| # | |
| backend default { | |
| .host = "127.0.0.1"; | |
| .port = "8000"; | |
| # health check: every 5 secs, sliding window of 5 checks of which 3 must be good | |
| .probe = { | |
| .url = "/"; | |
| .interval = 5s; | |
| .timeout = 1s; | |
| .window = 5; | |
| .threshold = 3; | |
| } | |
| } | |
| # another backend: | |
| backend nodejs { | |
| .host = "127.0.0.1"; | |
| .port = "8001"; | |
| } | |
| sub vcl_recv { | |
| # strip google analytics cookies | |
| if (req.http.Cookie) { | |
| # removes all cookies named __utm? (utma, utmb...) - tracking thing | |
| set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *__utm.=[^;]+;? *", "\1"); | |
| if (req.http.Cookie == "") { | |
| remove req.http.Cookie; | |
| } | |
| } | |
| # add another header if we got a request via pound (SSL forwarding) | |
| # @todo this needs to be improved! | |
| if (req.http.x-forwarded-for) { | |
| set req.http.X-Forwarded-For-2 = req.http.X-Forwarded-For; | |
| } | |
| # Rewrite all requests to /node/ to nodejs backend: | |
| if (req.url ~ "^/node/") { | |
| set req.http.host = "127.0.0.1"; | |
| set req.http.port = 8001; | |
| set req.backend = nodejs; | |
| remove req.http.Cookie; | |
| return(lookup); | |
| } | |
| if (! req.backend.healthy) { | |
| # allow serving of up to 30min old objects if the backend | |
| # is down | |
| set req.grace = 30m; | |
| } else { | |
| # allow serving of up to 30sec old objects in order to | |
| # fight flashmobs and not overloading the backend | |
| set req.grace = 30s; | |
| } | |
| # large file workaround (see below) | |
| if (req.http.x-pipe && req.restarts > 0) { | |
| remove req.http.x-pipe; | |
| return (pipe); | |
| } | |
| # cookie handling for pimcore frontend step 1 | |
| if(req.http.Cookie ~ "(pimcore_admin_sid|PHPSESSID)" || req.url ~ "(PHPSESSID|pimcore_admin_sid)" || req.url ~ "nocache") { | |
| set req.http.X-Forwarded-For = client.ip; | |
| return(pass); | |
| } | |
| # cookie handling for pimcore backend step 2 | |
| if ( !( req.url ~ "^/admin/") ) { | |
| unset req.http.Cookie; | |
| } | |
| } | |
| sub vcl_fetch { | |
| # keep items in the cache for up to 30min beyond TTL | |
| set beresp.grace = 30m; | |
| # Requests w/ auth headers always pass the cache, direct backend! | |
| if (req.http.Authorization) { | |
| return(hit_for_pass); | |
| } | |
| # large file workaround: dont cache files >10mb | |
| # http://education.nixsupport.com/2012/10/varnish-reports-error-503-for-large.html | |
| if (beresp.http.Content-Length ~ "[0-9]{8,}" ) { | |
| set req.http.x-pipe = "1"; | |
| return (restart); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment