Too Many Redirects - CDN Rewrite Rule

Francis Daly francis at
Fri Mar 22 09:27:24 UTC 2013

On Thu, Mar 21, 2013 at 06:48:43PM -0400, toddlahman wrote:

Hi there,

> The reply I received from NetDNA after supplying the same information as I
> did here is as follows:
> "Too many redirects" is a legit message in this scenario - example: You are
> redirecting TO ---> request
> comes to CDN and CDN neds to cache this file from origin so it tries to
> fetch from origin from location "" ---> request comes to
> origin and redirect rule you made redirects this request back to CDN <---
> this is where infinite loop starts.

Ah, okay, that makes sense. You don't upload to the CDN; it instead
mirrors your content on demand. (That was the part I had missed.)

As was mentioned, the correct solution is for all of your links to
actually be to things like; but as was
also mentioned, that is not a quick change for you.

The NetDNA suggestion -- to serve when it comes from them and to redirect
when it comes from others -- is reasonable; but as they also indicate,
"when it comes from them" is non-trivial to get right, and will be a
problem if you ever get it wrong in one direction.

Using proxy_pass in your nginx would defeat the main purpose of using
a CDN, as your own bandwidth would be used always.

An alternative possibility could be for you to set up another
server{} block with a server_name of (say) which
has the same document root as your main one, but which just serves
the static files.  Then, at the point where your CDN is configured to
map ->, map it instead to

With no change to your application, your users go to
and follow a link to; your "main" server redirects
them to; they get that, which fetches (now
successfully) and returns it to the user.

Does that sound like it might do what you want, without taking too
much effort to keep synchronised?

Francis Daly        francis at

More information about the nginx mailing list