Welcome! Log In Create A New Profile


Re: nginx proxy_pass and proxy_cache

Francis Daly
November 11, 2021 03:56AM
On Wed, Nov 10, 2021 at 08:58:54PM +0200, Reinis Rozitis wrote:

Hi there,

> > 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/?

Assuming that other proxy criteria are the same, I think that the "map"
suggestion with a variable for proxy_cache will be the simplest.

But if you have reasons to want more explicit config:

> 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/;
> }

I think that that one would fail for the same reason as the initial
attempt: proxy_pass-with-URI and regex location do not go well together.

http://nginx.org/r/proxy_pass :

In some cases, the part of a request URI to be replaced cannot be determined:

lists three cases, and this is case#1.

As it happens, you *can* do it if you take advantage of case#3.

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

(although you probably want to capture to a named variable, instead of
hoping that $1 has not changed by the time proxy_pass uses it -- see
http://nginx.org/en/docs/http/server_names.html#regex_names and choose
the syntax that your version uses. Probably (?<this_bit>.*\.xml), and
then use $this_bit.)

You could possibly also take advantage of case#2, and do

rewrite /something/(.*\.xml)$ /$1 break;

but that feels a bit too subtle to me.

Note that the regex-matching attempts may not do what you want if you
have %-encodings in the incoming requests -- test your use cases to see
that things work for you.

Or just use the map.

Good luck with it,

Francis Daly francis@daoine.org
nginx mailing list
Subject Author Posted

nginx proxy_pass and proxy_cache

Michiel Beijen November 10, 2021 10:30AM

RE: nginx proxy_pass and proxy_cache

Reinis Rozitis November 10, 2021 02:00PM

Re: nginx proxy_pass and proxy_cache

Francis Daly November 11, 2021 03:56AM

Re: nginx proxy_pass and proxy_cache

Francis Daly November 11, 2021 04:04AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 114
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready