我的NGINX服务器块中有以下位置块:
location ~ ^/admin {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?uri=$1;
}
}
但它不起作用。 /etc/nginx/.htpasswd文件存在并使用htpasswd命令生成:
sudo htpasswd -c /etc/nginx/.htpasswd admin
之前我已经完成了这项工作,但这次它刚刚停止工作。这次唯一的区别是我这次尝试在重写块内部执行auth_basic_user_file。
答案 0 :(得分:0)
该配置无效,因为重写阶段if XYZ
将始终在访问阶段auth_XYZ
之前运行,无论您如何在位置块中排列它们。
除了已有的身份验证要求之外,还需要将身份验证要求添加到php块中。