how to setup as caching reverse proxy for/rewritign global URLs

Francis Daly francis at
Sun Mar 3 22:54:51 UTC 2019

On Wed, Feb 20, 2019 at 12:37:23PM +0100, Thomas Hartmann wrote:

Hi there,

> I would like to setup Nginx as a caching reverse proxy but with explicit
> requests in the URL and rewriting all subsequent requests

"caching reverse proxy" is what nginx is built for.

"rewriting the body content" is not.

> Don;t know, if it really counts as reverse proxy and if it is
> understandable, so an example ;)

The first part of what you want is probably reasonable; the second part
is probably going to involve you writing your own code.

> For an original URL like
>    https://org.url.baz/user/repo/foo
> I would like to be able to cache all request through nginx running at
> but with an explicit "cache request" like
>   wget

Your original "https" has become "http" in the middle here. That may or
may not be intentional.

> and rewrite all subsequent request and cache them.
> So, I am looking for something similar to Internet Archive's memento proxy
> Since my idea is no 'true' reverse proxy, the example [1] needs probably
> a bit of extension and I am not sure, how to do the rewrites.

You want to take the $request_uri you were given, remove the leading
"/cache/", make sure the rest looks like a url, and proxy_pass to that.

And then take any string in the response body that the browser might
interpret as a url, and make sure that you rewrite it as necessary so
that it expands to the url you need it to be.

Rather than start from scratch, you might have more luck seeing if you
can find the code that Internet Archive's memento proxy uses.

I suspect that it is not "merely" clever nginx config; but it may give
you an idea of the kind of things you will need to do in your version.

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list