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 have different files inside three different directories.

I'd like to block access to all files inside those (also block directory listing).

This way, I'd block, for example:

  • /a/b/file

  • /a/c/file

  • /a/d/file

Whatever the file extension...

This is what I am trying:

location /a/(b|c|d) {
    allow; #IP
    deny all;
    return 403;

But it's not working.

share|improve this question
up vote 4 down vote accepted

You need ~ in your location config - without it means literal prefix matching, while you're attempting to use regex syntax.

location ~ /a/(b|c|d) {
share|improve this answer
Is the allow; #IP in the right position? Should it come after "deny all;" and "return 403"? – Roger Oct 9 '11 at 23:00
Yes, the order is right: – quanta Oct 10 '11 at 2:27

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.