【发布时间】:2021-12-28 19:54:48
【问题描述】:
我的目录结构如下:
/home
/home/static
/home/static/image1.png
/home/static/pdf1.pdf
我想用密码保护www.mypage.com/uploads 的访问并可视化当前在该目录中的文件的索引,但如果有人转到www.mypage.com/uploads/pdf1.pdf,则不应验证请求并在不询问密码的情况下显示文件。
到目前为止,我有以下 nginx 配置,它要求我在 /uploads 路径以及 /uploads/pdf1.pdf 上输入用户名和密码。
Nginx 配置
location /uploads {
alias /home/static/;
autoindex on;
auth_basic "Private Route";
auth_basic_user_file /etc/apache2/.htpasswd;
}
[编辑] 建议的工作解决方案:
location ~/uploads$ {
alias /home/static/;
autoindex on;
auth_basic "Private Route";
auth_basic_user_file /etc/apache2/.htpasswd;
}
location /uploads {
alias /home/static/;
autoindex off;
auth_basic off;
}
【问题讨论】:
标签: nginx password-protection nginx-config nginx-location