Nginx regex location not matching

nginxregex

I have the below location below, which is among a larger conf file.

As reference, this works:

location = /scripts/news/admin/index.js {
       alias /my/file/path/news/scripts/admin/index.js;
}

This however, fails to pick up the regex (as a test I am forcing the file path, but it is still not used):

location ^~ ^/scripts/([a-z]+)/([a-z]+)/([a-z]+).js$ {
        alias /my/file/path/news/scripts/admin/index.js; # for testing, use direct file location
        break; # ensuring nothing else happens, for testing
        #alias /my/file/path/$1/scripts/$2/$3.js; # actual regex
}

Am I missing something glaringly obvious in my regex? I've tried (.*) and ~* but neither makes any difference. The URL being used is:

http://example.com/scripts/news/admin/index.js

In my logs I see:

2015/03/21 20:43:28 [debug] 16440#0: *183689 test location: "^/scripts/(\w+)/(\w+)\.js$"
2015/03/21 20:43:28 [debug] 16440#0: *183689 test location: "/"
2015/03/21 20:43:28 [debug] 16440#0: *183689 test location: "scripts/([a-z]+)/([a-z]+)/([a-z]+).js"
2015/03/21 20:43:28 [debug] 16440#0: *183689 test location: "thirdparty"
2015/03/21 20:43:28 [debug] 16440#0: *183689 test location: "skins"
2015/03/21 20:43:28 [debug] 16440#0: *183689 test location: ~ "\.(jpg|jpeg|gif|css|png|js|ico|html)$"
2015/03/21 20:43:28 [debug] 16440#0: *183689 using configuration "\.(jpg|jpeg|gif|css|png|js|ico|html)$"

Why isn't thethird entry catching and stopping?

Best Answer

I presumed that regex matches went most specific first, not order written first. The final regex shown in my log was matching and stopping.