Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am new to nginx and I really enjoy how fast it is in combination with php-fpm.

I want to protect a folder with

    location / {
            try_files $uri $uri/ $uri.php /;
            auth_basic "restricted";
            auth_basic_user_file /www/config/global.passwd;

this works by accessing /, but on hitting /test.php it does not ask for a password. It does ask for one at /test/ so this only works for folders.

How to include files for protection?

share|improve this question
At a guess, you have a location block for handling PHP files and /test.php is matching that block and not the one you have posted above. Try /test.htm and see if you get the same result to verify. – cyberx86 Jul 31 '13 at 12:59
That's it.. how can I combine or avoid to make several containers for each folder with php files :-S – DanFromGermany Jul 31 '13 at 13:20
up vote 2 down vote accepted

With the help of this:

How to use FastCGI globally and Basic Auth in sublocations in nginx?

I solved the problem by putting location containers into other location containers.

Thx cyberx86 for the initial hint.

share|improve this answer

Your Answer


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.