V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
neodreamer
V2EX  ›  服务器

虽然这个需求很奇葩,但我想问下有没有可能

  •  
  •   neodreamer · 2015-12-18 10:21:16 +08:00 via Android · 2541 次点击
    这是一个创建于 3023 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Apache 服务器能不能禁用目录浏览 但是可以直接访问目录下的具体文件。

    比如 file 目录下的 1.PDF 可以直接通过 /file/1.PDF 直接访问,但是 访问 /file/ 时 Apache 不罗列处该目录下的所有文件。禁用 index 可以不罗列目录,但是 目录下的文件也不能访问了。


    这种需求只是提高了一点点安全性 而且是自欺欺人的,但想问下是否可以实现。
    12 条回复    2015-12-18 10:57:42 +08:00
    learnshare
        1
    learnshare  
       2015-12-18 10:27:55 +08:00   ❤️ 1
    neodreamer
        2
    neodreamer  
    OP
       2015-12-18 10:30:26 +08:00
    这里没 VPN 我用 Bing 搜索下你给的关键词,之间搜索过 apache conf 关键词,没发现有用的。
    yylzcom
        3
    yylzcom  
       2015-12-18 10:30:54 +08:00   ❤️ 1
    "禁用 index 可以不罗列目录,但是 目录下的文件也不能访问了"
    这句话不成立,禁用 index 恰好就是实现你的需求,不列出目录且能直接访问文件
    yylzcom
        4
    yylzcom  
       2015-12-18 10:32:27 +08:00   ❤️ 1
    如果还不行,你就设置 apache ,随便弄一个空白 index.html, index.shtml 的文件进去,访问目录的时候就访问这个文件,而不会列出目录下的文件了。
    neodreamer
        5
    neodreamer  
    OP
       2015-12-18 10:35:11 +08:00
    <Directory "E:/Server">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important. Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    # AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
    </Directory>

    现在的系统设置, Options FollowSymLinks (原先是 Options Indexes FollowSymLinks )这种设置也导致目录下的内容访问不了如 http://projectstrike.test/attachment/1447832084.pdf (用的 Cakephp 框架)
    neodreamer
        6
    neodreamer  
    OP
       2015-12-18 10:37:02 +08:00
    @yylzcom 难道是跟框架.htaccess 设置有关系?

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ webroot/ [L]
    RewriteRule (.*) webroot/$1 [L]
    </IfModule>
    neodreamer
        7
    neodreamer  
    OP
       2015-12-18 10:37:20 +08:00
    @learnshare 感谢已发送。
    Tink
        8
    Tink  
       2015-12-18 10:38:31 +08:00 via iPhone   ❤️ 1
    你把目录浏览禁用了,然后本来就能通过文件访问
    neodreamer
        9
    neodreamer  
    OP
       2015-12-18 10:41:40 +08:00
    @Tink 我的设想是访问目录时禁止罗列目录下的所有文件,但是如果知道目录下的具体文件名称时,可以直接通过链接直接访问。
    strahe
        10
    strahe  
       2015-12-18 10:42:43 +08:00   ❤️ 1
    本身就支持的又不是什么特别的需求
    neodreamer
        11
    neodreamer  
    OP
       2015-12-18 10:53:04 +08:00
    @strahe 囧,发现了,自己犯了个严重错误,实际上 把 Options Indexes FollowSymLinks 改成 Options FollowSymLinks 就可以了。感谢楼上各位鼎力相助。
    neodreamer
        12
    neodreamer  
    OP
       2015-12-18 10:57:42 +08:00
    麻烦管理员把这个帖子移到 水节点下。

    的确太水了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4537 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:07 · PVG 18:07 · LAX 03:07 · JFK 06:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.