Takeaway: This software can boost the performance of any website and serve up to a million pages with only a small virtual private server.
sub vcl_recv{ if(req.url ~ " * \.(png|gif|jpg|swf|css|js)"{ unset req.http.cookie; unset req.http.Vary; return(lookup); } # strip the cookie before the image is inserted into cache. sub vcl_fetch { if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") { unset beresp.http.set-cookie; }
sub vcl_recv{ # Let's make sure we aren't compressing already compressed formats. if (req.http.Accept-Encoding) { if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|mp3|mp4|m4v)(\?. * |)$") { 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 { remove req.http.Accept-Encoding; } } if (req.url ~ "^/$") { unset req.http.cookie; } # Unset all cookies if not Wordpress admin - otherwise login will fail if (!(req.url ~ "wp-(login| admin )")) { unset req.http.cookie; return(lookup); } # If you request the special pages go directly to them if (req.url ~ "wp-(login| admin )") { return (pipe); } } sub vcl_miss { if (!(req.url ~ "wp-(login| admin )")) { unset req.http.cookie; } if (req.url ~ "^/[^?]+.(jpeg|jpg|png|gif|ico|js|css|txt|gz|zip|lzma|bz2|tgz|tbz|html|htm)(\?.|)$") { unset req.http.cookie; set req.url = regsub(req.url, "\?.$", ""); } if (req.url ~ "^/$") { unset req.http.cookie; } } sub vcl_fetch { if (req.url ~ "^/$") { unset beresp.http.set-cookie; } # Unset all cookies if not Wordpress admin - otherwise login will fail if (!(req.url ~ "wp-(login| admin )")) { unset beresp.http.set-cookie; } }
sub vcl_recv { if (req.backend.healthy) { set req.grace = 30s; } else { set req.grace = 1h; } } sub vcl_fetch { set beresp.grace = 1h; }
# # Customized VCL file for serving up a Wordpress site with multiple back-ends. # # Define the internal network subnet. # These are used below to allow internal access to certain files while not # allowing access from the public internet . acl internal { "10.100.0.0"/24; } # Define the list of our backends (web servers), they Listen on port 8080 backend web1 { .host = "10.100.0.1"; .port = "8080"; .probe = { .url = "/status.php"; .interval = 5s; .timeout = 1s; .window = 5;.threshold = 3; }} backend web2 { .host = "10.100.0.2"; .port = "8080"; .probe = { .url = "/status.php"; .interval = 5s; .timeout = 1s; .window = 5;.threshold = 3; }} # Define the director that determines how to distribute incoming requests. director default_director round-robin { { .backend = web1; } { .backend = web2; } } # Respond to incoming requests. sub vcl_recv { set req.backend = default_director; # Use anonymous, cached pages if all backends are down. if (!req.backend.healthy) { unset req.http.Cookie; set req.grace = 6h; } else { set req.grace = 30s; } # Unset all cookies if not Wordpress admin - otherwise login will fail if (!(req.url ~ "wp-(login| admin )")) { unset req.http.cookie; return(lookup); } # If you request the special pages go directly to them if (req.url ~ "wp-(login| admin )") { return (pipe); } # Always cache the following file types for all users. if (req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm)(\?[ a- z0-9]+)?$") { unset req.http.Cookie; } } # Code determining what to do when serving items from the web servers. sub vcl_fetch { # Don't allow static files to set cookies. if (req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm)(\?[ a- z0-9]+)?$") { # beresp == Back-end response from the web server. unset beresp.http.set-cookie; } # Allow items to be stale if needed. set beresp.grace = 6h; }
Tags: Software Linux
Riccardo Capecchi has been a Unix/Linux system administrator since 1999. In his spare time, he writes articles about the open source world on his blog at linuxaria.com.
Subscribe to one of our free newsletters now for the best of Techopedia.