Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- backend apache {
- .host = "127.0.0.1";
- .port = "81";
- .max_connections = 256;
- .connect_timeout = 30s;
- .first_byte_timeout = 30s;
- .between_bytes_timeout = 30s;
- # need to create ping.html in public_html directory with just a line like "PONG!"
- .probe = {
- .url = "/ping.html";
- .timeout = 10s;
- .window = 8;
- .threshold = 3;
- }
- }
- acl purge {
- "localhost";
- }
- sub vcl_recv {
- set req.http.host = "example.net";
- #purge all
- if (req.request == "PURGE") {
- if (!client.ip ~ purge) {
- error 405 "Not allowed.";
- }
- if (req.url ~ "varnish/index/purgeall/key/#Fj1nzljh") {
- purge( ".*" );
- }
- }
- #described below need to create random "DynamicPage" value; this functionallity we use
- #to create several caches for 1 dynamic page.
- #for example, "int i = rand() % 2 + 1;" means that we have 2 different copies of one dynamic page
- # C{
- # char buffer [33];
- # int i = rand() % 10 + 1;
- # sprintf(buffer, "%d", i);
- # VRT_SetHdr(sp, HDR_REQ, "\014DynamicPage:", buffer, vrt_magic_string_end);
- # }C
- if (req.request != "GET" &&
- req.request != "HEAD" &&
- req.request != "PUT" &&
- req.request != "POST" &&
- req.request != "TRACE" &&
- req.request != "OPTIONS" &&
- req.request != "DELETE") {
- return (pipe);
- }
- # do not cache POST requests
- if (req.request == "POST") {
- return (pipe);
- }
- #we should not cache any page for Magento backend
- if (req.request == "GET" && (req.url ~ "^/admin") || req.url ~ "^/index.php/admin") {
- return (pass);
- }
- #we should not cache any page for checkout and customer modules
- if (req.request == "GET" && (req.url ~ "^/checkout" || req.url ~ "^/customer")) {
- return (pass);
- }
- #do not cache till session end
- if (req.http.cookie ~ "nocache_stable") {
- return (pass);
- }
- #unique identifier witch tell Varnish use cache or not
- if (req.http.cookie ~ "nocache") {
- return (pass);
- }
- if (req.request == "GET" && (req.url ~ "\.(png|jpg|jpeg|gif)$" || req.url ~ "print.css")) {
- return (lookup);
- }
- #Even though there are few possible values for Accept-Encoding, Varnish treats
- #them literally rather than semantically, so even a small difference which makes
- #no difference to the backend can reduce cache efficiency by making Varnish cache
- #too many different versions of an object.
- #http://varnish.projects.linpro.no/wiki/FAQ/Compression
- if (req.http.Accept-Encoding) {
- if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
- # No point in compressing these
- 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 {
- # unkown algorithm
- remove req.http.Accept-Encoding;
- }
- }
- return (lookup);
- }
- sub vcl_pipe {
- # Note that only the first request to the backend will have
- # X-Forwarded-For set. If you use X-Forwarded-For and want to
- # have it set for all requests, make sure to have:
- # set req.http.connection = "close";
- # here. It is not set by default as it might break some broken web
- # applications, like IIS with NTLM authentication.
- return (pipe);
- }
- sub vcl_pass {
- return (pass);
- }
- sub vcl_hit {
- if (!obj.cacheable) {
- return (pass);
- }
- return (deliver);
- }
- sub vcl_miss {
- return (fetch);
- }
- sub vcl_fetch {
- return (deliver);
- }
- sub vcl_deliver {
- if (obj.hits > 0) {
- set resp.http.X-Cache = "HIT";
- } else {
- set resp.http.X-Cache = "MISS";
- }
- }
- sub vcl_error {
- set obj.http.Content-Type = "text/html; charset=utf-8";
- synthetic {"
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html>
- <head>
- <title>"} obj.status " " obj.response {"</title>
- </head>
- <body>
- <h1>Error "} obj.status " " obj.response {"</h1>
- <p>"} obj.response {"</p>
- <h3> :</h3>
- <p>URL: "} obj.http.bhash {"</p>
- <p>XID: "} req.xid {"</p>
- <hr>
- <address>
- <a href="http://www.varnish-cache.org/">Nexcess cache server</a>
- </address>
- </body>
- </html>
- "};
- return (deliver);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement