【发布时间】:2018-08-05 13:24:25
【问题描述】:
我有一个目录public,我将在其中上传各种文件。我希望这些文件无需任何身份验证即可下载。
但是,如果提供了身份验证,我还希望能够使用 WebDAV 编辑和添加新文件。有什么办法可以让我在同一个目录(位置)上同时拥有这两种行为?
我尝试了以下技巧:
location /public/ {
if ($remote_user != "") {
return 302 e;
}
auth_basic off;
fancyindex off;
dav_methods off;
}
location /public/e {
}
但是,我找不到将/public/e 改为索引/public/ 的方法。
我还尝试了以下方法:
location /public/ {
if ($remote_user = "") {
auth_basic off;
fancyindex off;
dav_methods off;
}
}
但是 Nginx 抱怨我不能在 if 语句中包含这些指令。
我也试过了:
location /public/ {
set $authenticated off;
if ($remote_user != "") {
set $authenticated on;
}
auth_basic $authenticated;
fancyindex $authenticated;
dav_methods $authenticated;
}
但是 Nginx 说一个变量无效,on 或 off 应该是。
我还考虑过创建两个目录,public 和 public-webdav,它们符号链接到同一个目录,并为它们分配不同的 nginx 位置,但我希望有一个更干净的解决方案。
谢谢!
【问题讨论】:
标签: authentication nginx web webdav