Last active
          June 19, 2021 01:35 
        
      - 
      
- 
        Save matthewjackowski/8e118f1f7e2aef5b5eb2a03631e734f7 to your computer and use it in GitHub Desktop. 
Revisions
- 
        Matthew Jackowski revised this gist May 14, 2016 . 1 changed file with 32 additions and 31 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -19,12 +19,12 @@ sub vcl_recv { # Setting http headers for backend set req.http.X-Forwarded-For = client.ip; set req.http.X-Forwarded-Proto = "https"; # Unset headers that might cause us to cache duplicate infos unset req.http.Accept-Language; unset req.http.User-Agent; unset req.http.Vary; # Redirect www to non-www if (req.http.host ~ "^www\.") { @@ -39,49 +39,50 @@ sub vcl_recv { } # Redirect mobile to homepage if (req.url ~ "/mobile/$" || req.url ~ "/m/$" ) { set req.url = "/"; set req.http.x-redir = "https://" + req.http.host + req.url; return (synth(750, "Moved permanently")); } # Weird things bing looks for if (req.url ~ "sitemap\.aspx") { set req.url = "/sitemap_index.xml"; set req.http.x-redir = "https://" + req.http.host + req.url; return (synth(750, "Moved permanently")); } if (req.url ~ "aboutus\.aspx$") { set req.url = "/about/"; set req.http.x-redir = "https://" + req.http.host + req.url; return (synth(750, "Moved permanently")); } # drop params from static asset if (req.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") { set req.url = regsub(req.url, "\?.*$", ""); } # drop tracking params if (req.url ~ "\?(utm_(campaign|medium|source|term)|adParams|client|cx|eid|fbid|null|feed|ref(id|src)?|v(er|iew))=") { set req.url = regsub(req.url, "\?.*$", ""); } unset req.http.cookie; } sub vcl_backend_response { # retry a few times if backend is down if (beresp.status == 503 && bereq.retries < 3 ) { return(retry); } if (bereq.url ~ "\.(css|js|ttf)(\?.*|)$") { unset beresp.http.cookie; unset beresp.http.Set-Cookie; set beresp.ttl = 1d; unset beresp.http.Cache-Control; } if (beresp.ttl < 120s) { unset beresp.http.cookie; unset beresp.http.Set-Cookie; set beresp.ttl = 120s; 
- 
        Matthew Jackowski revised this gist Apr 11, 2016 . 1 changed file with 1 addition and 19 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -64,20 +64,8 @@ sub vcl_recv { if (req.url ~ "\?(utm_(campaign|medium|source|term)|adParams|client|cx|eid|fbid|feed|ref(id|src)?|v(er|iew))=") { set req.url = regsub(req.url, "\?.*$", ""); } unset req.http.cookie; } sub vcl_backend_response { @@ -86,12 +74,6 @@ sub vcl_backend_response { return(retry); } if (bereq.url ~ "\.(css|js|ttf)(\?.*|)$") { unset beresp.http.cookie; unset beresp.http.Set-Cookie; 
- 
        Matthew Jackowski revised this gist Apr 10, 2016 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -92,6 +92,12 @@ sub vcl_backend_response { set beresp.ttl = 30s; return (deliver); } if (bereq.url ~ "\.(css|js|ttf)(\?.*|)$") { unset beresp.http.cookie; unset beresp.http.Set-Cookie; set beresp.ttl = 1d; unset beresp.http.Cache-Control; } if (beresp.ttl < 120s) { unset beresp.http.cookie; 
- 
        Matthew Jackowski revised this gist Apr 10, 2016 . 1 changed file with 13 additions and 13 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -39,21 +39,21 @@ sub vcl_recv { } # Redirect mobile to homepage if (req.url ~ "/mobile/$" || req.url ~ "/m/$" ) { set req.url = "/"; set req.http.x-redir = "https://" + req.http.host + req.url; return (synth(750, "Moved permanently")); } # Weird things bing looks for if (req.url ~ "sitemap\.aspx") { set req.url = "/sitemap_index.xml"; set req.http.x-redir = "https://" + req.http.host + req.url; return (synth(750, "Moved permanently")); } if (req.url ~ "aboutus\.aspx$") { set req.url = "/about/"; set req.http.x-redir = "https://" + req.http.host + req.url; return (synth(750, "Moved permanently")); } # drop params from static assets if (req.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") { 
- 
        Matthew Jackowski revised this gist Apr 10, 2016 . 1 changed file with 19 additions and 2 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -33,11 +33,28 @@ sub vcl_recv { } # Redirect http to https if ( std.port(server.ip) == 80) { set req.http.x-redir = "https://" + req.http.host + req.url; return (synth(750, "Moved permanently")); } # Redirect mobile to homepage if (req.url ~ "/mobile/$" || req.url ~ "/m/$" ) { set req.url = "/"; set req.http.x-redir = "https://" + req.http.host + req.url; return (synth(750, "Moved permanently")); } # Weird things bing looks for if (req.url ~ "sitemap.aspx$") { set req.url = "/sitemap_index.xml"; set req.http.x-redir = "https://" + req.http.host + req.url; return (synth(750, "Moved permanently")); } if (req.url ~ "aboutus.aspx$") { set req.url = "/about/"; set req.http.x-redir = "https://" + req.http.host + req.url; return (synth(750, "Moved permanently")); } # drop params from static assets if (req.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") { set req.url = regsub(req.url, "\?.*$", ""); 
- 
        Matthew Jackowski revised this gist Apr 5, 2016 . 1 changed file with 6 additions and 11 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -24,6 +24,7 @@ sub vcl_recv { # Unset headers that might cause us to cache duplicate infos unset req.http.Accept-Language; unset req.http.User-Agent; unset req.http.Vary; # Redirect www to non-www if (req.http.host ~ "^www\.") { @@ -68,26 +69,20 @@ sub vcl_backend_response { return(retry); } # Don't store backend if (bereq.url ~ "wp-(login|admin)" || bereq.url ~ "preview=true") { set beresp.uncacheable = true; set beresp.ttl = 30s; return (deliver); } if (beresp.ttl < 120s) { unset beresp.http.cookie; unset beresp.http.Set-Cookie; set beresp.ttl = 120s; unset beresp.http.Cache-Control; } # remove extra headers unset beresp.http.X-Powered-By; unset beresp.http.Server; 
- 
        Matthew Jackowski revised this gist Apr 5, 2016 . 1 changed file with 33 additions and 28 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -46,6 +46,20 @@ sub vcl_recv { if (req.url ~ "\?(utm_(campaign|medium|source|term)|adParams|client|cx|eid|fbid|feed|ref(id|src)?|v(er|iew))=") { set req.url = regsub(req.url, "\?.*$", ""); } # pass if admin url if (req.url ~ "(wp-login|wp-admin)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php") { return (pass); } # pass if admin cookies if (req.http.cookie) { if (req.http.cookie ~ "(wordpress_|wp-settings-)") { return(pass); } else { unset req.http.cookie; } } } sub vcl_backend_response { @@ -54,35 +68,26 @@ sub vcl_backend_response { return(retry); } # For static content strip all backend cookies if (bereq.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") { unset beresp.http.cookie; } # Don't store backend if (bereq.url ~ "wp-(login|admin)" || bereq.url ~ "preview=true") { set beresp.uncacheable = true; set beresp.ttl = 30s; return (deliver); } # Only allow cookies to be set if we're in admin area if (!(bereq.url ~ "(wp-login|wp-admin|preview=true)")) { unset beresp.http.set-cookie; } # remove extra headers unset beresp.http.X-Powered-By; unset beresp.http.Server; 
- 
        Matthew Jackowski revised this gist Apr 2, 2016 . 1 changed file with 6 additions and 20 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import std; # Backend setup backend default { .host = "brilliantcoding.us"; .port = "80"; } @@ -46,20 +46,6 @@ sub vcl_recv { if (req.url ~ "\?(utm_(campaign|medium|source|term)|adParams|client|cx|eid|fbid|feed|ref(id|src)?|v(er|iew))=") { set req.url = regsub(req.url, "\?.*$", ""); } } sub vcl_backend_response { @@ -98,11 +84,11 @@ sub vcl_backend_response { # unset cookies from backendresponse unset beresp.http.set-cookie; # remove extra headers unset beresp.http.X-Powered-By; unset beresp.http.Server; unset beresp.http.Via; unset beresp.http.X-Pingback; unset beresp.http.X-Varnish; } 
- 
        Matthew Jackowski revised this gist Apr 2, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -8,8 +8,8 @@ import std; # Backend setup backend default { .host = "ec2-52-24-255-72.us-west-2.compute.amazonaws.com"; .port = "80"; } sub vcl_recv { 
- 
        Matthew Jackowski renamed this gist Apr 1, 2016 . 1 changed file with 13 additions and 3 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -17,9 +17,6 @@ sub vcl_recv { # Only a single backend set req.backend_hint= default; # Setting http headers for backend set req.http.X-Forwarded-For = client.ip; set req.http.X-Forwarded-Proto = "https"; @@ -49,6 +46,19 @@ sub vcl_recv { if (req.url ~ "\?(utm_(campaign|medium|source|term)|adParams|client|cx|eid|fbid|feed|ref(id|src)?|v(er|iew))=") { set req.url = regsub(req.url, "\?.*$", ""); } # pass if admin url if (req.url ~ "(wp-login|wp-admin)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php") { return (pass); } # pass if admin cookies if (req.http.cookie) { if (req.http.cookie ~ "(wordpress_|wp-settings-)") { return(pass); } else { unset req.http.cookie; } } } 
- 
        Matthew Jackowski revised this gist Apr 1, 2016 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,6 @@ # Sets forwarded proxy headers # Custom error page vcl 4.0; import std; # Backend setup 
- 
        Matthew Jackowski revised this gist Apr 1, 2016 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -87,7 +87,13 @@ sub vcl_backend_response { } # unset cookies from backendresponse unset beresp.http.set-cookie; # remove extra headers unset resp.http.X-Powered-By; unset resp.http.Server; unset resp.http.Via; unset resp.http.X-Pingback; unset resp.http.X-Varnish; } 
- 
        Matthew Jackowski revised this gist Apr 1, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import std; # Backend setup backend default { .host = "192.168.99.100"; .port = "32777"; } 
- 
        Matthew Jackowski revised this gist Apr 1, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -9,8 +9,8 @@ import std; # Backend setup backend default { .host = "http://192.168.99.100"; .port = "32777"; } sub vcl_recv { 
- 
        Matthew Jackowski created this gist Apr 1, 2016 .There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,133 @@ # A basic setup for the edge # Strips cookies and un-needed params # Does a few redirects # Sets forwarded proxy headers # Custom error page vcl 4.0; import directors; import std; # Backend setup backend default { .host = "wordpress"; .port = "80"; } sub vcl_recv { # Only a single backend set req.backend_hint= default; # Drop cookies unset req.http.cookie; # Setting http headers for backend set req.http.X-Forwarded-For = client.ip; set req.http.X-Forwarded-Proto = "https"; # Unset headers that might cause us to cache duplicate infos unset req.http.Accept-Language; unset req.http.User-Agent; # Redirect www to non-www if (req.http.host ~ "^www\.") { set req.http.x-redir = regsub(req.http.host, "^www\.(.*)", "https://\1") + req.url; return (synth(750, "Moved permanently")); } # Redirect http to https if ( std.port(server.ip) == 80) { set req.http.x-redir = "https://" + req.http.host + req.url; return (synth(750, "Moved permanently")); } # drop params from static assets if (req.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") { set req.url = regsub(req.url, "\?.*$", ""); } # drop tracking params if (req.url ~ "\?(utm_(campaign|medium|source|term)|adParams|client|cx|eid|fbid|feed|ref(id|src)?|v(er|iew))=") { set req.url = regsub(req.url, "\?.*$", ""); } } sub vcl_backend_response { # retry a few times if backend is down if (beresp.status == 503 && bereq.retries < 3 ) { return(retry); } # if we get a session cookie...caching is a no-go if (bereq.http.Cookie ~ "(UserID|_session)") { set beresp.http.X-Cacheable = "NO:Got Session"; set beresp.uncacheable = true; return (deliver); } elsif (beresp.ttl <= 0s) { # Varnish determined the object was not cacheable set beresp.http.X-Cacheable = "NO:Not Cacheable"; } elsif (beresp.http.set-cookie) { # Don't cache content for logged in users set beresp.http.X-Cacheable = "NO:Set-Cookie"; set beresp.uncacheable = true; return (deliver); } elsif (beresp.http.Cache-Control ~ "private") { # Respect the Cache-Control=private header from the backend set beresp.http.X-Cacheable = "NO:Cache-Control=private"; set beresp.uncacheable = true; return (deliver); } else { # Object is cacheable set beresp.http.X-Cacheable = "YES"; } # unset cookies from backendresponse unset beresp.http.set-cookie; } sub vcl_hash { if ( req.http.X-Forwarded-Proto ) { hash_data( req.http.X-Forwarded-Proto ); } } sub vcl_synth { # redirect for http if (resp.status == 750) { set resp.status = 301; set resp.http.Location = req.http.x-redir; return(deliver); } # display custom error page if backend down if (resp.status == 503) { set resp.status = 404; synthetic(std.fileread("/etc/varnish/error.html")); return(deliver); } } sub vcl_deliver { # oh noes backend is down if (resp.status == 503) { return(restart); } if (obj.hits > 0) { set resp.http.X-Cache = "HIT"; } else { set resp.http.X-Cache = "MISS"; } set resp.http.Access-Control-Allow-Origin = "*"; } sub vcl_hit { } sub vcl_miss { } 
 Matthew Jackowski
              revised
            
            this gist
            
              Matthew Jackowski
              revised
            
            this gist