internal, redirects and proxy_cache

Nic Ferrier nic at ferrier.me.uk
Sat Jun 22 09:10:25 UTC 2013


A very related question was asked before here:

http://forum.nginx.org/read.php?2,236720,236782#msg-236782

But I'm not sure that asked exactly what I want to do.


I've got locations like this:

    location /packages/archive-contents {
        proxy_pass http://localhost:8005;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /packages/archive-contents/ {
        internal;
        proxy_pass http://localhost:8005;
        proxy_http_version 1.1;
    }


The first one calls out to the app server which sends an X-Forwarded-For
to the second one, something like:

    http://host/packages/archive-contents/38381632639138

I would like to cache that response so that nginx hit the app server
from the first location which redirects to the 2nd location but that
returns a cached response. 

When the redirect from the first location changes the second location
would have to cache it.


Is that possible? I've tried adding proxy_cache to the 2nd location,
like so:

    location /packages/archive-contents/ {
        internal;
        proxy_pass http://localhost:8005;
        proxy_http_version 1.1;
        proxy_cache marmaladerepo-cache;
        proxy_cache_valid  200 302  1d;
        proxy_cache_valid  404      60m;
    }

but this doesn't seem to have an effect.




Nic Ferrier



More information about the nginx mailing list