nginx regex characters that require quoting?

Posted by Michael Louis Thaler on Server Fault See other posts from Server Fault or by Michael Louis Thaler
Published on 2011-10-07T17:15:59Z Indexed on 2013/06/25 22:23 UTC
Read the original article Hit count: 476

Filed under:
|
|

So I was configuring nginx today and I hit a weird problem. I was trying to match a location like this:

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

...for URLs like "http://my.domain.com/0001/index.html".

This rule was never matching, despite the fact that it by all rights should. It took me awhile to figure out, based on this documentation, that some characters in regexes need to be quoted. The problem is, the documentation is for rewrites, and it specifically calls out curly braces, not square brackets. After a fair bit of experimentation that involved a lot of swearing, I discovered that I could fix the problem by quoting the regex like so:

location ~ "^/([0-9]+)/(.*)" {
    # do proxy redirects
}

Is there a list somewhere of characters that nginx requires quoting regexes with? Or could there be something else going on here that I'm totally missing? This is my first nginx configuration job, so it's very possible I've misunderstood something...

© Server Fault or respective owner

Related posts about nginx

Related posts about proxy