我已经成功地在我的nginx 1.6.2上设置了清漆4,它正在工作,但根据testing
http://www.isvarnishworking.com/
表明
Varnish看起来是在那个url上响应的,但是Cache-Control头的“max-age”值是小于1的,这意味着Varnish永远不会在这个url上从caching中提供内容。
- 如何从Postgres 9.1升级到9.3,在升级过程中允许读取访问
- Postfix服务器拒绝发件人地址
- 将Ganglia和Nagios用于一台服务器是否过分矫枉过正?
- Xen 4.4混合路由/桥接networkingvm不起作用
- OpenVPN忽略openvpn.conf,引发无法识别或丢失的选项
最大年龄值看起来是:0
这可能是故意的,但是如果你想让Varnishcaching这个URL,你将不得不修复应用程序发送给Varnish的最大年龄值。
这意味着它不工作,但不是预期的,searchconfiguration文件,但由于清漆版本4的巨大变化那些configuration文件不起作用。
请帮帮我吧。
谢谢
对此的解决scheme不在configuration清漆正确。 这个陈述有点过于强烈,你可以在Varnish中解决这个问题。 但是你不应该。
问题是,WordPress发送了一个标题,防止Varnishcaching它提供的对象。 您需要跟踪WordPress正在生成的头文件的位置,然后修改,禁用或覆盖它。
默认情况下,WordPress发送每个访问者一个Cookie,这使得Varnish认为每个访问者是唯一的,因此不应该被caching。
为了从Varnish中获得任何好处,您需要重写此行为,并在HTTP请求进入Varnish时“取消”或“移除”Cookie。
网上有很多关于这方面的文章,还有大量的Varnish VCL文件和例子,其中一个你可以在这里find: https : //www.varnish-cache.org/trac/wiki/VCLExampleTemplateWordpressNopurge
祝你好运!
我知道,复活一个旧的职位,但是想把这个放在这里面给所有遇到同样问题的人。
首先,您将要为未login的用户删除cookie。以下是我的vcl_recv子文件的一部分:
sub vcl_recv { # Some wordpress URL manipulation 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, "\?.*$", ""); } # Pass if the page is login, admin, preview, search or xmlrpc if (req.url ~ "wp-(login|admin)" || req.url ~ "preview=true" || req.url ~ "\?s=" || req.url ~ "xmlrpc.php") { return (pass); } # Some generic URL manipulation, useful for all templates that follow # First remove the Google Analytics added parameters, useless for our backend if (req.url ~ "(\?|&)(utm_source|utm_medium|utm_campaign|utm_content|gclid|cx|ie|cof|siteurl)=") { set req.url = regsuball(req.url, "&(utm_source|utm_medium|utm_campaign|utm_content|gclid|cx|ie|cof|siteurl)=([A-z0-9_\-\.%25]+)", ""); set req.url = regsuball(req.url, "\?(utm_source|utm_medium|utm_campaign|utm_content|gclid|cx|ie|cof|siteurl)=([A-z0-9_\-\.%25]+)", "?"); set req.url = regsub(req.url, "\?&", "?"); set req.url = regsub(req.url, "\?$", ""); } # Strip hash, server doesn't need it. if (req.url ~ "\#") { set req.url = regsub(req.url, "\#.*$", ""); } # Strip a trailing ? if it exists if (req.url ~ "\?$") { set req.url = regsub(req.url, "\?$", ""); } # Remove the wp-settings-1 cookie set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-1=[^;]+(; )?", ""); # Remove the wp-settings-time-1 cookie set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-time-1=[^;]+(; )?", ""); # Remove the wp test cookie set req.http.Cookie = regsuball(req.http.Cookie, "wordpress_test_cookie=[^;]+(; )?", ""); # Remove the cloudflare cookie set req.http.Cookie = regsuball(req.http.Cookie, "__cfduid=[^;]+(; )?", ""); # Remove the PHPSESSID in members area cookie set req.http.Cookie = regsuball(req.http.Cookie, "PHPSESSID=[^;]+(; )?", ""); # Remove the Quant Capital cookies (added by some plugin, all __qca) set req.http.Cookie = regsuball(req.http.Cookie, "__qc.=[^;]+(; )?", ""); # Are there cookies left with only spaces or that are empty? if (req.http.cookie ~ "^\s*$") { unset req.http.cookie; } #Drop ALL cookies sent to WordPress, except those originating from the URLs defined. if (!(req.url ~ "(wp-login|wp-admin|cart|my-account|checkout|addons|wordpress-social-login|wp-login\.php|forumPM|members)")) { unset req.http.cookie; } }
同样,在你的后端响应中,如果你没有login,你想删除cookies。你还需要指示varnish为beresp设置TTL,所以Age不总是显示0。
sub vcl_backend_response { if (!(bereq.url ~ "(wp-(login|admin)|login)")) { unset beresp.http.set-cookie; } set beresp.ttl = 1h; return (deliver); }
这是基础知识。