合并 2 个不同文件夹 nginx 的目录列表 [英] Merge directory listing for 2 different folders nginx

查看:56
本文介绍了合并 2 个不同文件夹 nginx 的目录列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个文件夹,例如 folder-a 和 folder-b,它们显示为 Nginx 文件资源管理器的一部分.我在下面有我的 Nginx 文件.我有一个问题陈述,例如文件夹 a 和文件夹 b 有时共享具有不同内容的公共子目录,例如

I have 2 folders like folder-a and folder-b and they are shown as part of the Nginx file explorer. I have my Nginx file below. I have a problem statement like folder-a and folder-b sometimes share common sub-directory with different content like

folder-a->sub-folder->1.txt
folder-b->sub-folder->2.txt

所以当用户查看文件夹 folder-a->sub-folder 或 folder-b>sub-folder 时,他应该能够看到 1.txt 和 2.txt,即它应该感觉像是一个统一的视图.我可以实现这是nginx吗?

so when the user is viewing folder folder-a->sub-folder or folder-b>sub-folder he should be able to see both 1.txt and 2.txt i.e. it should feel like a unified view. Can I achieve this is nginx?

worker_processes 1;

events { worker_connections 1024; }

http {
    include /etc/nginx/mime.types;
    server {
        server_name localhost;
        listen 80;
        root /usr/share/nginx/html;
        
        autoindex on;               
        autoindex_exact_size off;   
        autoindex_localtime on;
        
         location ~ ^/folder-a/(.+)$ {
           error_page 404 @redirect;
        }

        location @redirect {
            return 301 /folder-b/$1;
        }
    }
}

推荐答案

未测试,但由于我们可以指定自动索引的输出格式,因此可能有解决方案/配置来打印创建新目录列表.

Not tested but as we can specify the output format of the autoindex there may be solutions / configuration to print create a new directory listing.

http://nginx.org/en/docs/http/ngx_http_autoindex_module.html

但它总是会打印/显示"当前文件夹的内容.鉴于如果您想合并两个不同文件夹的文件列表,njs 可以在这里提供帮助.

But it will always "print / show" the current folders content. Given that if you want to combine the filelist of two different folders njs could help here.

类似于使用 autoindex = on 配置的服务器和诸如 jsonxml 之类的可用格式.njs 可以查询两个目录并重建新的输出(xml、json).

Something like a server that is configured with autoindex = on and a useable format like json or xml. njs could query both directories and reconstruct a new output (xml, json).

未经测试,只是一个奇思妙想.

Not tested just a fancy idea.

这篇关于合并 2 个不同文件夹 nginx 的目录列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆