misunderstood regex location

Igor Sysoev igor at sysoev.ru
Tue May 6 06:55:48 UTC 2014


On May 6, 2014, at 2:38 , dcaillibaud wrote:

> Hi,
> 
> I understood that prefix location was read, then regex location and it stops
> on a ^~ match
> 
> Why with this config
> 
>      location / { 
>          location ~ .+\.(js|css|ico|png|gif|jpg|jpeg|pdf|zip|html|htm)$ {
>              expires 25h;
>          }
>      }
> 
>      location ^~ /banniere_rotative/.+\.(js|css)$ {
>              expires 30d;
>      }
> 
> https://ssl.sesamath.net/banniere_rotative/_writable/slides_20140503c.min.css
> match the first one prefix location and not the second regex one ?
> 
> After deeper tests, I saw that 
> 
>        location /banniere_rotative/ {
>            location ~ \.(js|css)$ {
>                    expires 30d;
>            }
>        }
> 
> match but 
> 
> location ^~ "/banniere_rotative/.*\.css$" {
> 
> doesn't (inside prefix location or not)
> 
> What's the obvious mistake I made in my regex ?

As Francis has already mentioned regex location is

location ~ ^/banniere...

But this will not work as you expect.
First nginx will match "location /", then it will search regex
location inside this location and finally "location ~ .+\.(js|"
will be used. Your solution:

location /banniere_rotative/ {

is right.


-- 
Igor Sysoev
http://nginx.com




More information about the nginx mailing list