Bypass Nginx cache when receiving a specific request

$uri holds a normalized url, it can be modified by any other directive or by a redirect. Things can be more complicated if your nginx config gets longer & longer. I prefer $request_uri (According to nginx documentation: full original request URI with arguments).

Try to replace your condition with this one:

if($request_uri ~ ServerCheck) {set $nocache 1; }

Btw, You don't need to capture your target string ServerCheck, since nginx just tests the regex.

Also you may want to be sure that request has been replied by proxy. I use add_header directive for this job. Such as:

add_header X-Proxy-Cache $upstream_cache_status;