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

I'm using nginx and want to restrict access to a directory to everyone except myself. I want to access the php scripts in /restricted. I've tried a few things so far. If I recall, this works to block access to all except the allowed ip, but all scripts are pushed to download instead of processed now.

location ~ /restricted { allow 1.2.3.4; deny all; }

share|improve this question

migrated from stackoverflow.com Jun 11 '11 at 22:47

This question came from our site for professional and enthusiast programmers.

    
pushed to download? could you explain a bit further? –  DarkCthulhu Jun 11 '11 at 20:41
    
The .php file in /restricted is downloaded rather than parsed as php. I may have to create a @block to pass the .php in /restricted. –  Poe Jun 11 '11 at 21:16
    
if /restricted is taking precedence over your "*.php$" handler block, your scripts will act like normal files –  lunixbochs Jun 12 '11 at 0:34
add comment

1 Answer

up vote 3 down vote accepted

You'll need a second (I prefer nested) php block since you want these php files handled differently. Also, assuming that /restricted is supposed to be a uri prefix and not just something that appears anywhere in the uri, you want a different type of location:

# This handles everything that starts with /restricted,
# and no regex locations will override it
location ^~ /restricted {
  allow 1.2.3.4;
  deny all;

  # This will inherit the allow/deny from the outer location
  location ~ \.php$ {
    include fastcgi.conf;
    fastcgi_pass backend;
  }
}
share|improve this answer
    
That's what I needed. Thanks –  Poe Jun 12 '11 at 1:35
add comment

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.