代码之家  ›  专栏  ›  技术社区  ›  AnotherJoe

仅主文件夹中的nginx autoindex子文件夹

  •  1
  • AnotherJoe  · 技术社区  · 7 年前

    我的文件夹结构:

    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\u backup\u某物。com/媒体/

    文件夹folder\u main\u 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\u other应该是一些regex,这样我就可以访问test\u媒体后面的所有文件夹。。。

    1 回复  |  直到 7 年前
        1
  •  3
  •   AnotherJoe    7 年前

    经过数小时的测试和阅读regex上无数的TUT:

        location /test_media {
    
            root /var/www/html/;
    
            autoindex off;
            }
    
        location ~ /test_media/test_other/(.+)  {
    
            root /var/www/html/;
    
            autoindex on;
            }   
    

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