nginx http auth只处理文件夹,而不是文件

我是nginx新手,我非常喜欢它与php-fpm结合的速度。

我想保护一个文件夹

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

这是通过访问/ ,但打在/test.php它不要求密码。 它确实要求在/test/所以这只适用于文件夹。

如何包含文件以进行保护?

在这个帮助下:

如何在nginx的sublocations中全局使用FastCGI和Basic Auth?

http://wiki.nginx.org/HttpCoreModule#location

我通过将location容器放入其他location容器来解决问题。

Thx cyberx86的最初提示。