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

另一个乔

我的文件夹结构:

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 后面的所有文件夹......

另一个乔

经过数小时的测试和阅读无数关于正则表达式的文章:

    location /test_media {

        root /var/www/html/;

        autoindex off;
        }

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

        root /var/www/html/;

        autoindex on;
        }   

我仍然不知道它为什么起作用或它是如何起作用的,但是......它起作用了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章