nginx proxy_pass and proxy_cache

Reinis Rozitis r at roze.lv
Wed Nov 10 18:58:54 UTC 2021


> And I can't make a location block for a mimetype, or using another specifier than regexes to filter out requests to certain 'file types'. Is there any other 'good' solution except for, on my origin adding rewrites from /something/data1/ to /data1/?


Why just not separate the locations rather make them nested?

Something like:

location /something/ {
  proxy_cache disk_cache;
  proxy_pass   http://origin/data1/;
}

location ~* ^/something/.*\.xml$ {
       proxy_cache fast_disk_cache;
       proxy_pass   http://origin/data1/;
}


If you don't want to multiply the whole location { proxy_pass } configuration you can use the map directive (http://nginx.org/en/docs/http/ngx_http_map_module.html) and just change the proxy_cache on the fly (you can easily add multiple cache locations this way):

map $request_uri $cache {
     ^/something/.*\.xml fast_disk_cache;
      default disk_cache;
}

server {
 location /something/ {
   proxy_cache $cache;
   proxy_pass   http://origin/data1/;
 }
}


rr



More information about the nginx mailing list