Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx location regex, match multiple times

Tags:

regex

nginx

How to match multiple times in nginx location regex ?

it seems the {x,x} syntax never works!

for example:

location ~ ^/abc/\w{1,3}$ {
  ...
}

nerver work!

like image 982
lovespring Avatar asked Mar 18 '23 12:03

lovespring


1 Answers

You must quote location which contains { or ; characters.

location ~ "^/abc/\w{1,3}$" {
    ...
}

otherwise nginx parse it as location ~ ^/abc/\w { 1, ... and fails with syntax error.

like image 173
Alexey Ten Avatar answered Mar 27 '23 19:03

Alexey Ten