variable capture in Nginx location matching

Old thread but I had the same problem…

I think the error isn’t related to the PCRE version installed

NGINX doesn’t parse your regex if your location tag doesn’t start with ~
You need to use something like this

location ~ ^/a/b/(?<myvar>[a-zA-Z]+) {
   # use variable $myvar here
   if ($myvar = "sth") { ... }
}

Leave a Comment