nginx simple regex location

Solution 1:

Try this

location ~ "^/[\d]{5}" {
    # ...
}

~ means the a regex location

^ means the beginning of the line

[\d] is shorthand for character class matching digits

{5} shows that the digits must be exactly five, no more, no less

and () parentheses are not necessary if you do not want then to use grouping, $1, for example

Double quotes because curley braces used in regex must be enclosed in double quotes: https://stackoverflow.com/questions/14684463/curly-braces-and-from-apache-to-nginx-rewrite-rules

Solution 2:

Try this syntax (tested on my server) :

location ~ ^/([0-9]+) {
  #...
}