nginx autoindex只在主文件夹中的子文件夹

时间:2018-03-04 15:03:10

标签: nginx

我的文件夹结构:

folder_main_x/
- folder_a
- folder_b
- folder_c
- ...

folder_main_y/
- folder_d
- folder_e
- folder_f
- ...

folder_main_z/
- folder_g
- folder_h
- folder_i
   - ...

 folder_main_.../
  -...

他们应该可以在这个域名下访问:

www.sync_backup_something.com/media /

文件夹folder_main_xyz ...应该是403(或更好的自定义错误消息),但是其他所有文件夹应该可以访问。

目前我试图用一些正则表达式来解决这个问题,但到目前为止还没有成功。

https://www.scalescale.com/tips/nginx/nginx-location-directive/

编辑:

此处仅适用于一个特定文件夹:

location /test_media {

    root /var/www/html/;

    autoindex off;
    }

location /test_media/test_other {

    root /var/www/html/;

    autoindex on;
    }   

但是test_other应该是一些正则表达式,所以我可以访问test_media背后的所有文件夹......

1 个答案:

答案 0 :(得分:0)

经过几个小时的测试并阅读了正则表达式的无数次:

    location /test_media {

        root /var/www/html/;

        autoindex off;
        }

    location ~ /test_media/test_other/(.+)  {

        root /var/www/html/;

        autoindex on;
        }   

我仍然不知道它为什么会起作用或者它是如何工作的,但是......它很有效。