nginx proxy_pass and proxy_cache

Michiel Beijen michiel.beijen at
Wed Nov 10 15:29:21 UTC 2021

Hi there,

I use nginx as caching reverse proxy.

I have requests coming as  /something/data1/request123.xml
I have other requests coming in as /something/data1/bigfile424.bin

I want to forward all requests to an origin on /data1/

Currently I use a location block:

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

This works great! Except the disk is rather slow and while the bin files
are mostly static and can be cached pretty good, the xml files, which
receive an awful lot of requests, update rather quickly. I prefer to cache
them on a FAST disk cache (or rather on a tmpfs partition). So now I would

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

As we know, proxy_pass does not inherit so I have to specify it also in the
nested location. But I can't use proxy_pass like this with a URI in a
location block containing a regex. 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/?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list