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

Thomas Hartmann thomas.hartmann at
Wed Feb 20 11:37:23 UTC 2019

Hi all,

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

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

For an original URL like
I would like to be able to cache all request through nginx running at
but with an explicit "cache request" like


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.

So far my attempts [2] were not really successful - but then I have not
much experiences in that direction and would be grateful, if someone has
an idea for me?

Cheers and thanks,


http {
    proxy_cache_path  /data/nginx/cache  levels=1:2    keys_zone=STATIC:10m
    inactive=1d  max_size=10g;
    server {
#       server_name *;

        location /cache {
            rewrite ^(.*)$ /VirtualHostBase/cache$1 break;
            proxy_pass   ;
            proxy_cache_revalidate on;
            proxy_buffering        on;
            proxy_cache            STATIC;
            proxy_ignore_headers   Cache-Control;
            proxy_cache_valid      any  1d;
            proxy_cache_use_stale  error timeout invalid_header updating
                                   http_500 http_502 http_503 http_504;
            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;
            proxy_set_header X-Forwarded-Port 443;
            proxy_set_header Host $host;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5334 bytes
Desc: S/MIME Cryptographic Signature
URL: <>

More information about the nginx mailing list