Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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...

share|improve this question
    
Try with ^/(\d+)/(.*) to confirm whether it's the brackets or not. –  Shane Madden Oct 7 '11 at 17:25
    
That would explain lot of confusion :) –  tommics Sep 2 at 10:13

1 Answer 1

Do you need the number? I'd try a simpler variant first and see if the error is maybe something else.

I'd try if ^/[0-9]+/, or do you need the captured elements?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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