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; deny all; }

  • pushed to download? could you explain a bit further? – Anirudh Ramanathan 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

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 {
  deny all;

  # This will inherit the allow/deny from the outer location
  location ~ \.php$ {
    include fastcgi.conf;
    fastcgi_pass backend;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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