Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- backend default {
- .host = "127.0.0.1";
- .port = "8080";
- }
- acl purge {
- "localhost";
- }
- sub vcl_recv {
- # Modify HTTP X-Forwarded-For header.
- # This will replace Varnish's IP with actual client's.
- remove req.http.X-Forwarded-For;
- set req.http.X-Forwarded-For = client.ip;
- # Check the incoming request type is "PURGE", not "GET" or "POST"
- if (req.request == "PURGE") {
- # Check if the ip coresponds with the acl purge
- if (!client.ip ~ purge) {
- # Return error code 405 (Forbidden) when not
- error 405 "Not allowed.";
- }
- return (lookup);
- }
- # Get rid of progress.js query params
- if (req.url ~ "^/misc/progress\.js\?[0-9]+$") {
- set req.url = "/misc/progress.js";
- }
- # Do not cache these paths.
- if (req.url ~ "^/status\.php$" ||
- req.url ~ "^/update\.php" ||
- req.url ~ "^/install\.php" ||
- req.url ~ "^/admin" ||
- req.url ~ "^/admin/.*$" ||
- req.url ~ "^/user" ||
- req.url ~ "^/user/.*$" ||
- req.url ~ "^/users/.*$" ||
- req.url ~ "^/info/.*$" ||
- req.url ~ "^/flag/.*$" ||
- req.url ~ "^.*/ajax/.*$" ||
- req.url ~ "^.*/ahah/.*$") {
- return (pass);
- }
- # Pipe these paths directly to Apache for streaming.
- if (req.url ~ "^/admin/content/backup_migrate/export") {
- return (pipe);
- }
- if (req.http.Cookie)
- {
- set req.http.Cookie = ";" req.http.Cookie;
- set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
- set req.http.Cookie = regsuball(req.http.Cookie, ";(SESS[a-zA-Z0-9]*)=", "; \1=");
- set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
- set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
- if (req.http.Cookie == "") {
- remove req.http.Cookie;
- }
- }
- # if (req.url ~ "^/$") {
- # unset req.http.cookie;
- # }
- # Cache static content of themes.
- if (req.url ~ ".(css|js|png|gif|jp(e)?g)")
- {
- unset req.http.cookie;
- }
- return(lookup);
- }
- sub vcl_hit {
- if (req.request == "PURGE") {
- set obj.ttl = 0s;
- error 200 "Purged.";
- }
- }
- sub vcl_fetch {
- # if (req.url ~ "^/$") {
- # unset beresp.http.set-cookie;
- # }
- # if (!(req.url ~ "wp-(login|admin)")) {
- # unset beresp.http.set-cookie;
- # }
- }
- # Set a header to track a cache HIT/MISS.
- sub vcl_deliver {
- if (obj.hits > 0) {
- set resp.http.X-Varnish-Cache = "HIT";
- }
- else {
- set resp.http.X-Varnish-Cache = "MISS";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement