我的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"选项从htpasswd检查中排除"dir"目录。
当我尝试访问http://domain/dir/我看到除了php文件之外的所有文件,因为前面的指令要求我进行身份验证。
在apache上,我使用"满足任何"选项,但如果我在nginx上使用这个选项,对我来说不起作用,或者我放在了不正确的网站上。
我的目标是当我访问http://domain/dir/没有任何文件的身份验证。
谢谢!!
这是因为所有.php
文件都有单独的auth_basic
。
要在/dir/
中保存您的.php
文件,只需添加此位置块,并根据您的用例在该块内设置规则
location ~ /dir/(.+)'.php$ {
allow 1.2.3.4;
allow 127.0.0.1;
deny all;
auth_basic off;
}