Reconfiguring Which WordPress Pages to Cache

2 min

language: ja bn en es hi pt ru zh-cn zh-tw

Hello, I'm incompetent.

Until now, I had been caching everything except for the admin screen and truly problematic pages, but when I received a comment from mao-chan, it wasn't reflected!!! There was this problem, so I decided to revise my settings.

Below are the Nginx settings.

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; 
}

The red text indicates the added section.
This change ensures that only static content is cached, excluding comments and similar dynamic elements, and the cache is properly maintained.

The perceived speed is as fast as before adding this syntax, so it's better to configure it properly.

That's all.

Related Posts