Php 如何阻止Varnish缓存站点地图?
我正在运行一个关于Nginx和Varnish的Wordpress博客。我正在使用以下清漆配置:Php 如何阻止Varnish缓存站点地图?,php,wordpress,nginx,sitemap,varnish,Php,Wordpress,Nginx,Sitemap,Varnish,我正在运行一个关于Nginx和Varnish的Wordpress博客。我正在使用以下清漆配置: # This is a basic VCL configuration file for varnish. See the vcl(7) # man page for details on VCL syntax and semantics. # # Default backend definition. Set this to point to your content # server. #
# This is a basic VCL configuration file for varnish. See the vcl(7)
# man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# server.
#
backend default {
.host = "127.0.0.1";
.port = "8080";
.connect_timeout = 600s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
.max_connections = 800;
}
acl purge {
"localhost";
}
sub vcl_recv {
set req.grace = 2m;
# Set X-Forwarded-For header for logging in nginx
remove req.http.X-Forwarded-For;
set req.http.X-Forwarded-For = client.ip;
# Remove has_js and CloudFlare/Google Analytics __* cookies.
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_[_a-z]+|has_js)=[^;]*", "");
# Remove a ";" prefix, if present.
set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
# Either the admin pages or the login
if (req.url ~ "/wp-(login|admin|cron)") {
# Don't cache, pass to backend
return (pass);
}
# 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=[^;]+(; )?", "");
# Static content unique to the theme can be cached (so no user uploaded images)
# The reason I don't take the wp-content/uploads is because of cache size on bigger blogs
# that would fill up with all those files getting pushed into cache
if (req.url ~ "wp-content/themes/" && req.url ~ "\.(css|js|png|gif|jp(e)?g)") {
unset req.http.cookie;
}
# Even if no cookies are present, I don't want my "uploads" to be cached due to their potential size
if (req.url ~ "/wp-content/uploads/") {
return (pass);
}
# Check the cookies for wordpress-specific items
if (req.http.Cookie ~ "wordpress_" || req.http.Cookie ~ "comment_") {
# A wordpress specific cookie has been set
return (pass);
}
# allow PURGE from localhost
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
return (lookup);
}
# Force lookup if the request is a no-cache request from the client
if (req.http.Cache-Control ~ "no-cache") {
return (pass);
}
# Try a cache-lookup
return (lookup);
}
sub vcl_fetch {
#set obj.grace = 5m;
set beresp.grace = 2m;
}
sub vcl_hit {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}
sub vcl_miss {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}
我已经学习了教程
一切都很好,但我正在使用它在每次发布新帖子后动态生成站点地图。它生成一个名为sitemap\u index.xml
的站点地图索引,其中包含其他站点地图(用于帖子、页面、作者等)。这也很有效
子vcl\u recv
if (req.url ~ "\.xml(\.gz)?$") {
return (pass);
}
我不能给你确切的语法,但你应该通过管道*请求网站地图
*管道-匹配vcl中的请求,并指示它始终从服务器获取该请求。我无法给出确切的语法,但您应该管道*对站点地图的请求
*管道-匹配vcl中的请求,并指示它始终从服务器获取该请求。我无法给出确切的语法,但您应该管道*对站点地图的请求
*管道-匹配vcl中的请求,并指示它始终从服务器获取该请求。我无法给出确切的语法,但您应该管道*对站点地图的请求 *管道-匹配vcl中的请求,并指示它始终从服务器获取请求 如果我在子vcl_recv中包含以下内容,它会起作用吗 if(req.url~“.xml(.gz)?$”){ 返回(通行证); } 这将起作用。将其放在函数顶部附近。但请记住,这将阻止缓存所有.xml文件和所有.xml.gz文件。当然,您可能正在服务的大多数xml文件和xml.gz文件都是站点地图,如果它们不是,这仍然是一个考虑因素 如果我在子vcl_recv中包含以下内容,它会起作用吗 if(req.url~“.xml(.gz)?$”){ 返回(通行证); } 这将起作用。将其放在函数顶部附近。但请记住,这将阻止缓存所有.xml文件和所有.xml.gz文件。当然,您可能正在服务的大多数xml文件和xml.gz文件都是站点地图,如果它们不是,这仍然是一个考虑因素 如果我在子vcl_recv中包含以下内容,它会起作用吗 if(req.url~“.xml(.gz)?$”){ 返回(通行证); } 这将起作用。将其放在函数顶部附近。但请记住,这将阻止缓存所有.xml文件和所有.xml.gz文件。当然,您可能正在服务的大多数xml文件和xml.gz文件都是站点地图,如果它们不是,这仍然是一个考虑因素 如果我在子vcl_recv中包含以下内容,它会起作用吗 if(req.url~“.xml(.gz)?$”){ 返回(通行证); }
这将起作用。将其放在函数顶部附近。但请记住,这将阻止缓存所有.xml文件和所有.xml.gz文件。当然,您可能正在服务的大多数xml文件和xml.gz文件都是站点地图,如果不是,这仍然是一个考虑因素。请拆下这些线
if (req.url ~ "\.xml(\.gz)?$") {
return (pass);
}
返回(通过)是一个解决办法,但它不是你想如何使用清漆。
Varnish用于缓存页面和内容,如sitemap\u index.xml
您已经在VCL中实现了清除机制,因此处理sitemap\u index.xml
问题的最简单方法就是清除它
基本原则是只要没有新帖子,就需要缓存sitemap_index.xml
。然后,每次创建新帖子时,您必须通过发送以下HTTP请求(从官方文档(1)粘贴)通知Varnishsitemap_index.xml
不再有效:
因此,我想您可以选择手动编辑模块,或者使用Varnish HTTP Purge/WordPress模块(可能还可以手动对其进行黑客攻击)(2)
请删除这些行
if (req.url ~ "\.xml(\.gz)?$") {
return (pass);
}
返回(通过)是一个解决办法,但它不是你想如何使用清漆。
Varnish用于缓存页面和内容,如sitemap\u index.xml
您已经在VCL中实现了清除机制,因此处理sitemap\u index.xml
问题的最简单方法就是清除它
基本原则是只要没有新帖子,就需要缓存sitemap_index.xml
。然后,每次创建新帖子时,您必须通过发送以下HTTP请求(从官方文档(1)粘贴)通知Varnishsitemap_index.xml
不再有效:
因此,我想您可以选择手动编辑模块,或者使用Varnish HTTP Purge/WordPress模块(可能还可以手动对其进行黑客攻击)(2)
请删除这些行
if (req.url ~ "\.xml(\.gz)?$") {
return (pass);
}
返回(通过)是一个解决办法,但它不是你想如何使用清漆。
Varnish用于缓存页面和内容,如sitemap\u index.xml
您已经在VCL中实现了清除机制,因此处理sitemap\u index.xml
问题的最简单方法就是清除它
基本原则是只要没有新帖子,就需要缓存sitemap_index.xml
。然后,每次创建新帖子时,您必须通过发送以下HTTP请求(从官方文档(1)粘贴)通知Varnishsitemap_index.xml
不再有效:
因此,我想您可以选择手动编辑模块或使用