Welcome! Log In Create A New Profile

Advanced

Re: misunderstood regex location

May 06, 2014 11:03AM
I understand my mistake, thanks to both of you.

May I suggest to insist on this in http://nginx.org/en/docs/http/ngx_http_core_module.html#location, with a remark on the fact that ^~ is not usable with a regex, for example with

syntax:
location [ = | ^~ ] uri { ... }
location ~ | ~* regexUri { ... }
location @name { ... }

and adding there Igor advice (repeated many times in this forum like in http://forum.nginx.org/read.php?2,247529,247718 or http://forum.nginx.org/read.php?2,174517,174534#msg-174534), that it's a better practice to have a prefix location list at first level then put regex location within

Reviewing all my server definitions, I'm starting to imagine what a nightmare could be, with on the first level a mix of standard prefix location, ^~ and ~ ^/ ;-)

I was also wondering wich has precedence for /images/foo.jpeg in these case,

1) (I guess D, because ^/ before prefix shortcut regex)

location ^~ /images/ {
location ~* \.(gif|jpg|jpeg)$ {
[ configuration D ]
}
}

location ~* \.(gif|jpg|jpeg)$ {
[ configuration E ]
}


2) (I guess E but I'm not so sure), this can also be a pitfall example (how complicating things can lead to unexpected behaviour)

location /images/ {
location ~* \.(gif|jpg|jpeg)$ {
[ configuration D ]
}
}

location ~* \.(gif|jpg|jpeg)$ {
[ configuration E ]
}

2bis) this makes 2) understandable (more predictable)

location /images/ {
location ~* \.(gif|jpg|jpeg)$ {
[ configuration D ]
}
location ~* \.svg$ {
[ configuration D2 ]
}
}

location / {
location ~* \.(gif|jpg|jpeg|svg|pdf)$ {
// static stuff not in /images/
[ configuration E ]
}
}


PS: is there a way to preserve space in this forum to make code easier to read ? (I tried <pre>, <code> and [code])
Subject Author Posted

misunderstood regex location

dcaillibaud May 05, 2014 06:38PM

Re: misunderstood regex location

Francis Daly May 05, 2014 07:42PM

Re: misunderstood regex location

Igor Sysoev May 06, 2014 02:56AM

Re: misunderstood regex location

dcaillibaud May 06, 2014 11:03AM

Re: misunderstood regex location

B.R. May 06, 2014 01:28PM

Re: misunderstood regex location

dcaillibaud May 06, 2014 02:39PM

Re: misunderstood regex location

dcaillibaud May 06, 2014 02:53PM

Re: misunderstood regex location

B.R. May 07, 2014 09:14AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 72
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready