1

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...
   }
}

1 Answer 1

3

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.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .