Nginx - 从指定目录的htpasswd中排除php文件

时间:2015-10-27 16:51:46

标签: php nginx

我的nginx指令:

location / {
    index index.html index.php;
    auth_basic "Members Only";
    auth_basic_user_file /var/www/clients/client1/web1/web/.htpasswd_stats;
}

location ~ \.php$ {
    allow 1.2.3.4;
    allow 127.0.0.1;
    deny all;
    auth_basic "Members Only";
    auth_basic_user_file /var/www/clients/client1/web1/web/.htpasswd_stats;

}

location /dir/ {
    auth_basic off;

}

我使用' auth_basic off'排除' dir'的选项来自htpasswd检查的目录。

当我尝试访问http://domain/dir/时,我看到除了php文件之外的所有文件,因为前一个指令要求我进行身份验证。

在apache上我使用'满足任何'选项,但如果我在nginx上使用此选项,对我没有用,或者我放错了网站。

我的目标是当我访问http://domain/dir/时,没有任何文件的身份验证。

谢谢!

1 个答案:

答案 0 :(得分:1)

这是因为您对所有removeLayer个文件都有单独的auth_basic

要将.php文件保存在.php内,只需根据您的用例在此块中添加此位置块和设置规则

/dir/