1
location / { try_files "/wp-content/cache/all/${uri}index.html" $uri $uri/ /index.php?q=$uri&$args; } 

But if there is a visual editor used, I don't want to use the cache. So it should be

location / { if ($args ~ visual-editor){ try_files $uri $uri/ /index.php?q=$uri&$args; } try_files "/wp-content/cache/all/${uri}index.html" $uri $uri/ /index.php?q=$uri&$args; } 

Except it doesn't work because nginx is restrictive and weird to someone who mostly did apache configs.

I tried named locations, I tried a sub location to make it happy about using try_files, I don't want a rewrite, using the error code hack with named locations will cause query parameters to be removed which can't happen.

The idea is simple, don't load the cached html file if there's some exclusion I define. But nothing seems to work and the internet gives answers that never answer my question so asking here.

2
  • Ideally, your custom code should not allow such pages to be cached to begin with. Commented Jan 28, 2019 at 15:19
  • It's not my code, and the module for wordpress that does the caching actually should cache pages that have GET params as sometimes in wordpress those are different pages altogether. It does have excludes but they weren't working, one possibility for them not working was the excludes depended on making htaccess rules. Commented Jan 28, 2019 at 21:41

1 Answer 1

1

You cannot put try_files into an if block, but you can set a variable in the if block and use that to invalidate the first term of the try_files statement.

For example:

server { ... set $cache /wp-content/cache/all; if ($args ~ visual-editor) { set $cache /nonexistent; } location / { try_files $cache${uri}index.html $uri $uri/ /index.php?q=$uri&$args; } ... } 

See this caution on the use of if.

You must log in to answer this question.