if inside a location block is famously unreliable in nginx, and a chain of them for what is really a lookup is both slow and surprising.
map $request_uri $cache_bypass {
default 0;
"~*/checkout" 1;
"~*/cart" 1;
}
map $http_user_agent $is_bot {
default 0;
"~*bot|crawl|spider" 1;
}
server { proxy_cache_bypass $cache_bypass; }
A map is evaluated only when the variable is used and is a hash lookup rather than a sequence of tests, so it stays fast as it grows. It lives at the http level, which means one table serves every server block rather than being duplicated. Exact matches are tried before regular expressions, so putting the common cases as literals is worth doing once the table is large.