Apache-2.2
重新啟動 Varnish 時出現“‘input’ 處的語法錯誤”;default.vcl 有問題
這是我在大量閱讀和參考後建構的 default.vcl,清漆配置文件:
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 (e.g. 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 (e.g. sitemap) if (req.url ~ "\.(xml)$") { set beresp.ttl = 0m; }
但我不確定它是什麼。我在這裡做錯了什麼?
錯誤是由於第 62 行上的多餘空格,從配置(default.vcl)中的位置 19 開始,正如錯誤中明確指出的那樣:
set beresp.ttl = 0m; ------------------#---------
***注意:***表示
#
位置。