D
D
datafilterman2019-10-10 17:59:57
Nginx
datafilterman, 2019-10-10 17:59:57

How to cache in nginx backend responses only those pages that do not contain arguments?

The page /page/index.php has an href leading to
/page/index.php?arg=1 - shows the same page from the cache ( /page/index.php ) as if the if is ignored at all

location = /page/index.php {
        if ($is_args != "") {
              proxy_pass http://backend;
              break;
        }
        proxy_pass http://backend;
        proxy_cache nginx;
        proxy_cache_key $scheme$proxy_host$uri;
        proxy_ignore_headers Cache-Control Expires Set-Cookie;
        proxy_cache_valid 10m;
        proxy_cache_methods GET;
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2019-10-10
@datafilterman

Better instead of ifwhich, is evil , use proxy_cache_bypass:

location = /page/index.php {
  proxy_pass http://backend;
  proxy_cache nginx;
  proxy_cache_key $scheme$proxy_host$uri;
  proxy_ignore_headers Cache-Control Expires Set-Cookie;
  proxy_cache_valid 10m;
  proxy_cache_methods GET;

  # перечислить каждый из возможных параметров:
  proxy_cache_bypass $arg_a$arg_b$arg_c; 
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question