I want to add to this guide interesting thing related to hestiaCP nginx & cloudflare.
By default cloudflare will NOT cache static resources with wordpress
nginx template.
I do talk about this
On the screenshot it’s HIT. I.e. correct behavior. Means: static resources like js files, css files, images - cached by cloudflare and downloaded from cloudflare servers instead of my hestiaCP.
How to check?
CTRL + SHIFT + C or F12 in Edge or Google Chrome → Network tab.
CTRL + R or CTRL+F5 (mark button on screenshot above: “disable cache”)
and you will see headgears (if you click on any file).
You will see there MISS. This is default behavior.
But why? If you have enabled caching, and you have headers for cache (max-age) why do you have MISS?
Here is a thing: Default Cache Behavior · Cloudflare Cache (CDN) docs
I.e. you must to have have both: max-age & Cache-Control header public.
How have I fixed it for myself (i’m not sure that if this is right thing to do, I need some professional to comment this).
(i have ubuntu 22.04)
I went here: /usr/local/hestia/data/templates/web/nginx/php-fpm
and made copy-paste of these 2 files:
- wordpress.tpl
- wordpress.stpl
to:
- mywordpress.tpl
- mywordpress.spl
Inside both mywordpress files
in block:
try_files $uri $uri/ /index.php?$args;
location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
expires 30d;
fastcgi_hide_header "Set-Cookie";
}
I’ve added just 1 line:
add_header Cache-Control “public”;
So I got next looking block (in both files)
location / {
try_files $uri $uri/ /index.php?$args;
location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
expires 30d;
add_header Cache-Control "public";
fastcgi_hide_header "Set-Cookie";
}
After that I saved files.
And changed wordpress template in hestiaCP admin for website to mywordpress template.
Cleaned cached on Cloudflare side.
And now I have dramatically increased hit rate on cloudflare side.