With a strategically-placed rewrite
directive, you can append $uri
with a parameter on the progress of redirects, and check for this parameter to decide whether or not to redirect back to CDN.
Or you could also use proxy_set_header
directive when doing a request from the CDN back onto the main server1 site, and check for the existence of such HTTP header when processing requests on the main server1 site.