1

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?

  • 2
    if there are multiple location blocks that match, the first one defined will be chosen. Make sure your location regex block is defined higher than any other location blocks. – Martin Konecny Mar 21 '15 at 20:51
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.