I need to configure cdn with nginx for images. GeoIp is working fine, but i have a problem with images that are not found on cdn server.

I configured nginx the following way: Client requests the image from server1, server1 checks if the client is from "UK" is yes redirect to CDN server. but now lets say the image is not found on CDN server server how can i redirect back to server1 if CDN server is also from "UK". this will enter to endless loop...


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.