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/
location /gateway/ {
proxy_cache gateway_cache;
proxy_cache_valid 200 302 10m;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_hide_header Access-Control-Allow-Origin;
add_header 'Access-Control-Allow-Origin' '*' always;
rewrite ^/gateway/(.*) /$1 break;
proxy_pass $elb;
}