nginx http auth only working on folders, not on files
5,982
With the help of this:
How to use FastCGI globally and Basic Auth in sublocations in nginx?
http://wiki.nginx.org/HttpCoreModule#location
I solved the problem by putting location
containers into other location
containers.
Thx cyberx86 for the initial hint.
Related videos on Youtube
![Nishanth](https://lh4.googleusercontent.com/-SC4uTVzMqrU/AAAAAAAAAAI/AAAAAAAAA2k/hyDS5RwWUkA/photo.jpg?sz=256)
Author by
Nishanth
Updated on September 18, 2022Comments
-
Nishanth almost 2 years
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?
-
cyberx86 almost 11 yearsAt 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. -
Nishanth almost 11 yearsThat's it.. how can I combine or avoid to make several containers for each folder with php files :-S
-