# Deny directory abc denies directory abcd etc

**URL:** <https://www.ruby-forum.com/t/deny-directory-abc-denies-directory-abcd-etc/221973>\
**Category:** NGINX\
**Created:** [August 7, 2012, 7:31pm UTC](https://www.ruby-forum.com/t/deny-directory-abc-denies-directory-abcd-etc/221973 "2012-08-07T19:31:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [August 7, 2012, 7:31pm UTC](https://www.ruby-forum.com/t/deny-directory-abc-denies-directory-abcd-etc/221973/1 "2012-08-07T19:31:32Z")

</div>

Hi  
I’m new to this forum so I hope this hasn’t come up before I didn’t find  
anything by searching.

I’m using the following to block access to multiple directories:

location ~ /(abc|def|ghi) { deny all; access\_log off; log\_not\_found  
off; return 404;}

The problem I find is that if there is a file or directory beginning  
with the same three characters, it too is blocked. So, for example, a  
directory or file named abcd would also be blocked.

Is there a solution to this or is my code incorrect?

Thanks

Terry

Posted at Nginx Forum:

> **[deny directory abc denies directory abcd etc](https://forum.nginx.org/read.php?2,229406,229406#msg-229406)**
>
> Hi I'm new to this forum so I hope this hasn't come up before I didn't find anything by searching. I'm using the following to block access to multiple directories: location ~ /(abc|def|ghi) { deny all; access\_log off; log\_not\_found off; return 404;}

---

<div class="post-metadata">

**Author:** ![edtaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/13edae/32.png) [@edtaa](https://www.ruby-forum.com/u/edtaa)\
**Post date:** [August 7, 2012, 9:09pm UTC](https://www.ruby-forum.com/t/deny-directory-abc-denies-directory-abcd-etc/221973/2 "2012-08-07T21:09:05Z")

</div>

On Tue, 2012-08-07 at 13:30 -0400, edtaa wrote:

> Hi  
> I’m new to this forum so I hope this hasn’t come up before I didn’t find  
> anything by searching.
> 
> I’m using the following to block access to multiple directories:
> 
> location ~ /(abc|def|ghi) { deny all; access\_log off; log\_not\_found  
> off; return 404;}

Regex locations take precedence over literal locations. Change your  
regex to this:

location ~ /(abc|def|ghi)/?$

Cliff
