Proxy Caching ignore path

Francis Daly francis at
Wed Aug 7 07:28:28 UTC 2019

On Tue, Aug 06, 2019 at 10:27:57AM -0400, jvanetten wrote:

Hi there,

> I have a situation where I need to enable proxy cache for a gateway but
> anything that goes to /gateway/public/files/ I do not want to cache. I have
> tried nested locations and all kinds of configurations with no success. It
> usually lands up with 404 errors on /gateway/public/files/ the complete url
> includes a file reference like so /gateway/public/files/kd774831ldja3
> caching is working for anything going to /gateway/

In nginx, one request is handled in one location. Only the config in,
or inherited into, that location, matters.

And you can nest some location{}s, if you want to inherit config
between them.

So if I've understood what you want to do, the simplest way is probably
to add a nested

    location /gateway/public/files/ {
        proxy_cache off;
        rewrite ^/gateway/(.*) /$1 break;
        proxy_pass $elb;

within your current "location /gateway/ {" block.

"proxy_pass" does not inherit, so needs to be there.

"rewrite" does not inherit, so needs to be there.

"proxy_cache" does inherit, so needs to be disabled if you do not want
to proxy_cache things from upstream's /public/files/.

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list