Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having an issue with aliasing. I want to append up to the first 4 digits of the file as part of the directory. (like '../123456.jpg'=>'../123/123456.jpg' and '../12.png'=>'../12/12.png')

Here is what I have:

location ~ ^/i/gallery2/(\d{1,4})(.*)$ {
    alias /home/web/images/gallery/$1/$1$2;

This is the error I get:

nginx: [emerg] pcre_compile() failed: missing ) in "^/i/gallery2/(\d"

Anyone have any ideas how to get this to work? It looks like it has a problem with the "{1,4}" Is there another way to do want I want?

share|improve this question
you should accept @ShaneMadden solution, works perfectly! – Stefano Jun 1 '12 at 10:57
@Stefano Thanks for the reminder. It didn't let me accept it right away and then I forgot about it. – Echo Jun 1 '12 at 13:26
it happens to me all the time and for various reasons, this is why I tend to remember the others ;-) – Stefano Jun 1 '12 at 14:53
up vote 14 down vote accepted

It figures you're starting the contents of the location block. It figures wrong.

Wrap it in quotes:

location ~ "^/i/gallery2/(\d{1,4})(.*)$" {
share|improve this answer

Your Answer


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.