我们正在使用nginx站点conf提供对用户文件夹中文件的auth基本用户控制访问,并希望稍微增强索引视图。
用户的文件位于文件系统级别的/var/www/data/files/USER
中,以下内容似乎可以正常工作,以便用户登录时,他们看到的用户根/
确实在显示它们他们的用户文件夹。 (不确定是否有更好的方法,但这似乎可行)
当前有效:
auth_basic "Access restricted";
auth_basic_user_file /opt/nginx/.htpasswd;
root /var/www/data;
fancyindex on;
fancyindex_header "/fancyindex/header.html";
fancyindex_footer "/fancyindex/footer.html";
fancyindex_ignore "fancyindex";
location / {
alias /var/www/data/files/;
try_files $remote_user$uri \
$remote_user$uri/
=404;
}
实现FancyIndex module时,对于索引视图,有一条指令可以隐藏指向“父目录” ..
的链接,该链接为fancyindex_hide_parent_dir on
,但是我只想这样做如果它们位于用户根目录下,而不是位于用户根目录的下级子目录(或子目录的子目录等)中。 (当它们位于用户根目录中时,该链接存在,尽管它不允许他们实际向上导航至其用户根目录,但我仍要删除它)
对于nginx代码语法和可能的界限仍然是新的,我尝试了一些似乎不起作用的事情
这是尝试使用if
块的尝试...
if ( $uri = "/$remote_user/" ) {
fancyindex_hide_parent_dir on;
}
# this throws an error about `fancyindex_hide_parent_dir` not allowed here which I assume
# means inside of an if block because I tried that in both the server and location levels
我还尝试了一些额外的或修改的location
块的失败迭代,但没有任何效果。
同样的目标是,索引视图中的父目录链接在用户根目录顶部时不显示,但如果向下导航到子目录(在下面的任何级别),则显示该链接。
感谢您对if
或location
块逻辑的正确nginx语法有任何想法或帮助,以实现这一目标。