重新设置WordPress中应缓存的页面
大家好,我是无能。
之前除了管理界面等真正不应该缓存的页面外,我把所有页面都缓存了,但是当mao酱给我评论时,发现评论没有显示出来!!!于是我决定重新设置。
以下是nginx的配置。
set $do_not_cache 0;
set $skip_reason "";
set $bypass 0;
# 静的コンテンツのみキャッシュする
if ($request_uri ~* "\.(jpg|jpeg|png|webp|gif|mp4|css|js|ico|woff2)$") {
set $do_not_cache 0;
}
if ($remote_addr ~ "^(127.0.0.1)$") {
set $bypass $http_secret_header;
}
if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
set $do_not_cache 1;
set $skip_reason Cookie;
}
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|sitemap(_index)?.xml") {
set $skip_cache 1;
set $skip_reason URI;
}
红色字体是新增的部分。
这样一来,只有静态内容会被缓存,评论等将被排除在外,从而保持缓存。
体感速度与添加此语法之前一样快,所以最好还是好好设置一下。
结束。