清漆4 vcl不会编译

时间:2015-08-01 19:29:05

标签: wordpress varnish vcl

我正在尝试为wordpress网站创建一个清漆文件,但是我收到以下编译错误:

varnish_1   | Message from VCC-compiler:
varnish_1   | Unused acl purge, defined:
varnish_1   | ('input' Line 22 Pos 5)
varnish_1   | acl purge {
varnish_1   | ----#####--
varnish_1   |
varnish_1   | Running VCC-compiler failed, exited with 2
varnish_1   |
varnish_1   | VCL compilation failed
wp1_varnish_1 exited with code 2

vcl文件位于下方。如果你删除acl清除功能它完全正常。有任何想法吗?提前致谢。

#
# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and http://varnish-cache.org/trac/wiki/VCLExamples for more examples.

# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;
import directors;

# Default backend definition. Set this to point to your content server.
backend default {
    .host = "web";
    .port = "80";
}

acl purge {
    "localhost";
    "127.0.0.1";
}

#sub vcl_recv {
    # Happens before we check if we have this in cache already.
    #
    # Typically you clean up the request here, removing cookies you don't need,
    # rewriting the request, etc.
#}

#sub vcl_backend_response {
    # Happens after we have read the response headers from the backend.
    #
    # Here you clean the response headers, removing silly Set-Cookie headers
    # and other mistakes your backend does.
#}

#sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
    #
    # You can do accounting or modifying the final object here.
#}


sub vcl_init {
  # Called when VCL is loaded, before any requests pass through it. Typically used to initialize VMODs.
}


sub vcl_recv {

        if (req.method == "PURGE") {
      if (req.http.X-Purge-Method == "regex")
      {
        ban("req.url ~ " + req.url + " && req.http.host ~ " + req.http.host);
        return (synth(200, "Banned."));
      }
      else
      {
        return (purge);
      }
      }

        if (req.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
            unset req.http.cookie;
            set req.url = regsub(req.url, "\?.*$", "");
        }

        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, "\?.*$", "");
        }

      if (
            req.url ~ "^/wp-(login|admin)" || req.url ~ "/wp-cron.php" || req.url ~ "/wp-content/uploads/"
         || req.url ~ "preview=true"       || req.url ~ "xmlrpc.php"   || req.url ~ "\?s=" || req.url ~ "/choose-your-logo"
       || req.url ~ "/cart" || req.url ~ "/checkout" || req.url ~ "/my-account" || req.url ~ "/addons"
        ) {
            # do not use the cache
            return(pass); // DO NOT CACHE
        }

      # WooCommerce
        if (req.url ~ "\?add-to-cart=") {
            # do not use the cache
            return(pass); // DO NOT CACHE
        }

      # Kick DFind requests
        if (req.url ~ "^/w00tw00t") {
            return (synth(404, "Not Found"));
        }

      if (req.http.cookie) {
        # Google Analytics
        set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(__utm[a-z]+)=([^;]*)", "");
        set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(_ga)=([^;]*)", "");

        # Quant Capital
        set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(__qc[a-z]+)=([^;]*)", "");

        # __gad __gads
        set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(__gad[a-z]+)=([^;]*)", "");

        # Google Cookie consent (client javascript cookie)
        set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(displayCookieConsent)=([^;]*)", "");

        # Other known Cookies: remove them (if found).
        set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(__CT_Data)=([^;]*)", "");
        set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(WRIgnore|WRUID)=([^;]*)", "");


        # PostAction: Remove (once and if found) a ";" prefix followed by 0..n whitespaces.
        # INFO \s* = 0..n whitespace characters
        set req.http.Cookie = regsub( req.http.Cookie, "^;\s*", "" );

        # PostAction: Unset the header if it is empty or 0..n whitespaces.
        if ( req.http.cookie ~ "^\s*$" ) {
          unset req.http.Cookie;
        }
      }


      ###
      ### Normalize the Accept-Language header
      ### We do not need a cache for each language-country combination! Just keep en-* and nl-* for future use.
      ### https://www.varnish-cache.org/docs/4.0/users-guide/increasing-your-hitrate.html#http-vary
      if (req.http.Accept-Language) {
        if (req.http.Accept-Language ~ "^en") {
          set req.http.Accept-Language = "en";
        } elsif (req.http.Accept-Language ~ "^nl") {
          set req.http.Accept-Language = "nl";
        } else {
          # Unknown language. Set it to English.
          set req.http.Accept-Language = "en";
        }
      }
 }


# Drop any cookies Wordpress tries to send back to the client.
sub vcl_backend_response {

    if ( (!(bereq.url ~ "(wp-(login|admin)|login)")) || (bereq.method == "GET") ) {
        unset beresp.http.set-cookie;
        set beresp.ttl = 1h;
    }

    if (bereq.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
        set beresp.ttl = 48h;
    }

}

sub vcl_deliver {
   if (obj.hits > 0) {
     set resp.http.X-Cache = "HIT";
   } else {
     set resp.http.X-Cache = "MISS";
   }
}
sub vcl_hit {
  if (req.method == "PURGE") {
    return(synth(200,"OK"));
  }
}

sub vcl_miss {
  if (req.method == "PURGE") {
    return(synth(404,"Not cached"));
  }
}

1 个答案:

答案 0 :(得分:1)

编译器告诉你问题,你已经找到了解决方案,删除了名为purge的未使用的acl:

Unused acl purge, defined:

另一个选项是添加一个检查以仅允许从该acl中清除:

if (req.method == "PURGE") {
    if (!client.ip ~ purge) {
        error 405 "Not allowed.";
    }