Using 2 intersection of conditions for proxy_cache_bypass (avoiding logical if/and)

B.R. reallfqq-nginx at
Fri Jan 24 21:04:45 UTC 2014


On Fri, Jan 24, 2014 at 9:45 PM, Jeroen Ooms <jeroen.ooms at>wrote:

> However, this bypasses the cache when either $http_cache_control OR
> $is_get is set. How can I achieve to set proxy_cache_bypass when both
> http_cache_control AND $is_get are set?

​The logic you wish imply using a single variable in proxy_cache_bypass
which is set if and only if both $http_cache_control and $_is_get are set.

Does the following ​work?

map $request_method $is_get {
  default: "";
  GET "true";

set $bypass "true"; # Defaults to true

# Each map then deactivates the $bypass variable if one
# of the variables linked with the AND logic is empty
map $http_cache_control $bypass {
  default: "";
  "":      $bypass;

map $is_get $bypass {
  default: "";
  "":      $bypass;

proxy_cache_methods POST;
​​​​​proxy_cache_bypass $bypass;
*B. R.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list