下面是我经过大量阅读和引用后构build的default.vcl,varnishconfiguration文件:
backend default { .host = "127.0.0.1"; .port = "8080"; } acl purge { "localhost"; } # Called when a request is received sub vcl_recv { if (req.request == "BAN") { if(!client.ip ~ purge) { error 405 "Not allowed."; } ban("req.url ~ "+req.url+" && req.http.host == "+req.http.host); error 200 "Banned."; } if (req.request != "GET" && req.request != "HEAD" && req.request != "PUT" && req.request != "POST" && req.request != "TRACE" && req.request != "OPTIONS" && req.request != "DELETE") { return (pipe); } if (req.request != "GET" && req.request != "HEAD") { return (pass); } #Requests for login, admin, sign up, preview, password protected posts, admin-ajax or other ajax requests if (req.url ~ "(wp-login|wp-admin|wp-signup|preview=true|admin-ajax.php)" || req.http.Cookie ~ "(wp-postpass|wordpress_logged_in|comment_author_)" || req.http.X-Requested-With == "XMLHttpRequest" || req.url ~ "nocache" || req.url ~ "(control.php|wp-comments-post.php|wp-login.php|bb-login.php|bb-reset-password.php|register.php)") { return (pass); } remove req.http.cookie; return (lookup); } # Called after a document has been successfully retrieved from the backend sub vcl_fetch { if (beresp.status == 404 || beresp.status == 503 || beresp.status >= 500) { set beresp.ttl = 0m; return(hit_for_pass); } # Requests for login, admin, sign up, preview, password protected posts, admin-ajax or other ajax requests if (req.url ~ "(wp-login|wp-admin|wp-signup|preview=true|admin-ajax.php)" || req.http.Cookie ~ "(wp-postpass|wordpress_logged_in|comment_author_)" || req.http.X-Requested-With == "XMLHttpRequest" || req.url ~ "nocache" || req.url ~ "(control.php|wp-comments-post.php|wp-login.php|bb-login.php|bb-reset-password.php|register.php)") { return (hit_for_pass); } # Don't cache .xml files (eg sitemap) if (req.url ~ "\.(xml)$") { set beresp.ttl = 0m; } # Cache HTML # if (req.url ~ "\.(html|htm)$") { # set beresp.ttl = 60m; # } remove beresp.http.set-cookie; set beresp.ttl = 24h; return (deliver); }
保存完文件后,我尝试重新启动清漆时发生了这种情况:
user@host:~$ sudo service varnish restart * Stopping HTTP accelerator varnishd [fail] * Starting HTTP accelerator varnishd [fail] Message from VCC-compiler: Syntax error at ('input' Line 62 Pos 19) set beresp.ttl = 0m; ------------------#--------- Running VCC-compiler failed, exit 1 VCL compilation failed
这基本上意味着在我的default.vcl中这行代码有问题:
# Don't cache .xml files (eg sitemap) if (req.url ~ "\.(xml)$") { set beresp.ttl = 0m; }
但是我不确定它是什么。 我在这里做错了什么?
错误是由于第62行的额外空间,从configuration(default.vcl)中的位置19开始,如错误中明确指出的那样:
set beresp.ttl = 0m; ------------------#---------
注: #表示位置。