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.

What's the easiest way to restrict access to all files except one, where whole domain is served via FastCGI?

The problem occurring when below conf is used, is that I cannot access /dir (I'm asked for password in some kind of loop, correct login+password is not letting me in).

Besides, same fastCGI config is duplicated in location = /unrestricted_file.php and location ~ .php$.

Structure is:

server {
    location = /unrestricted_file.php {
       # FastCGI conf...
       break;
    }

    location / {
        root 
        index

        auth_basic "Restricted";
        auth_basic_user_file file;
    }

    location /dir {
        auth_basic "Restricted";
        auth_basic_user_file file;
    }


   location ~ \.php$ {
       auth_basic "Restricted";
       auth_basic_user_file file;
       # fastcgi_pass...
   }
}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can turn off auth for a location with auth_basic off. This would shorten your config file to something like this: (untested)

server {
    auth_basic "Restricted";
    auth_basic_user_file file;

    location = /unrestricted_file.php {
       auth_basic off;
       # fastcgi_pass...
    }

    location / {
        root 
        index

    }

   location ~ \.php$ {
       # fastcgi_pass...
   }
}

The "loop" comes from the fact that the auth for /dir is specified two times (/ and /dir). To magnify this, try to change the text to "Restricted path /" and "Restricted path /dir" and your loop should show you both messages alternating.

share|improve this answer
    
Thanks shellholic, maybe you could help me with related question on SO: stackoverflow.com/questions/4256363/… ? –  piobyz Nov 23 '10 at 15:01

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.