I’d like to add a variable with string fragments to keep certain pages/requests from caching. This works fine without a variable by adding in my custom stpl file:
if ($request_uri ~* "fragment0|fragment1|fragment2") {
set $no_cache 1;
}
However I’m running into a problem because I don’t understand the syntax or variable scope.
PROBLEM #1:
set $fragment_var '|fragment3'
if ($request_uri ~* "fragment0|fragment1|fragment2$fragment_var") {
set $no_cache 1;
}
Doesn’t evaluate correctly. I’ve tried all the variations I can think of in terms of single quotes, double quotes, ${fragment3} and inside/outside the “fragment0|fragment1|fragment2” string
Does anyone know the syntax to get that to work?
PROBLEM #2:
Setting:
set $fragment_var '|fragment3'
in .user.ini causes nginx config to fail. I also tried creating a separate public_html/test.conf in with set $fragment_var '|fragment3' and including it via stpl but I don’t understand the scope or where to insert the include so that is also failing.
I’ve spent a couple hours on this. Any help or alternate solutions would be greatly appreciated!
UPDATE: In my naivete, it looks like I can’t use variables in regular expressions, which explains problem 1.
Regarding problem 2, it was a syntax error on my part and I can include things just fine.
So I now have a different solution of adding an include below the stock conditionals. The include contains the same conditionals with the fragments I need for the individual domain.
if ($request_uri ~* "wp-admin/|/wp-json/|wp-.*.php|xmlrpc.php|index.php|/store.*|/cart.*|/my-account.*|/checkout.*") {
set $no_cache 1;
}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash|PHPSESSID") {
set $no_cache 1;
}
include %home%/%user%/web/%domain%/public_html/000-prod/.user.ini*;
If anyone has a smarter/more streamlined idea, please post. Thanks!
I already created a custom template per instructions at: Web Templates and FastCGI/Proxy Cache | Hestia Control Panel And solved the initial issues with loading cache exclude fragments saved in a public_html config file which is included in the custom template and not using variables in regex.
It seems like nginx config include directive will load ANY filename.ext but it sounds like you are saying done put nginx directives in .user.ini because php-fpm service uses that in it will mess it up. True?
BTW: Is .user.ini in place of php.ini?
Lastly (and related but off topic) I am writing php code to generate cache exclude fragments on a per wp app basis at the public_html level. I would be happy to contribute the code to the hestia wp cache plugin as that functionality is the main thing a non technical user would need in addition to use nginx/fastcgi with wp-admin. I will open issue at the github repo when I’m done as I think you are involved in that project.