0

I am faced with a non-negotiable requirement to set the value of proxy_cache_background_update dynamically.

The proxy_cache_background_update directive doesn't support a variable argument. It can only be literal on or literal off. So simply setting a variable with Lua and using it in the directive won't work.

proxy_cache_background_update is also disallowed in if blocks, so that hope is destroyed too.

(... and no, the directive is not supported by ndk.set_var either).

Is it somehow possible to define two almost-identical location or even server blocks that differ only by the value of proxy_cache_background_update, and to somehow employ Lua to have either one or the other block "win" depending on the Host header, completely dynamically without hardcoding any concrete Host values?

I am also willing to consider other creative solutions that somehow achieve control over the behavior normally governed by the proxy_cache_background_update directive, either altogether without using the directive, or by somehow causing it to be ignored in favor of the behavior dependent on Host.

  • What is the context? Why do you want to do this? Why do you say it's "non-negotiable"? If that were really true, you would have to change the nginx source code. Obviously there must be a limit to sanity somewhere. – Michael Hampton May 02 '19 at 15:44
  • This is a direct requirement. Some websites want the feature, others don't want it. Yet others will change their mind twice a week. And we shouldn't have to regenerate and reload configs for that. We are trying to avoid having separate nginx configurations for individual websites. – Szczepan Hołyszewski May 02 '19 at 15:47
  • The docs say you can use this in `server` or even `location` blocks. Why is that not good enough? I think there is still some important context missing here. – Michael Hampton May 02 '19 at 15:49
  • I am already doing it in a location block, but this location block is supposed to handle either case dynamically. – Szczepan Hołyszewski May 02 '19 at 15:53

0 Answers0