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

2015-12-18 10:21:16 +08:00
 neodreamer
Apache 服务器能不能禁用目录浏览 但是可以直接访问目录下的具体文件。

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


这种需求只是提高了一点点安全性 而且是自欺欺人的,但想问下是否可以实现。
2571 次点击
所在节点    服务器
12 条回复
learnshare
2015-12-18 10:27:55 +08:00
neodreamer
2015-12-18 10:30:26 +08:00
这里没 VPN 我用 Bing 搜索下你给的关键词,之间搜索过 apache conf 关键词,没发现有用的。
yylzcom
2015-12-18 10:30:54 +08:00
"禁用 index 可以不罗列目录,但是 目录下的文件也不能访问了"
这句话不成立,禁用 index 恰好就是实现你的需求,不列出目录且能直接访问文件
yylzcom
2015-12-18 10:32:27 +08:00
如果还不行,你就设置 apache ,随便弄一个空白 index.html, index.shtml 的文件进去,访问目录的时候就访问这个文件,而不会列出目录下的文件了。
neodreamer
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
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
2015-12-18 10:37:20 +08:00
@learnshare 感谢已发送。
Tink
2015-12-18 10:38:31 +08:00
你把目录浏览禁用了,然后本来就能通过文件访问
neodreamer
2015-12-18 10:41:40 +08:00
@Tink 我的设想是访问目录时禁止罗列目录下的所有文件,但是如果知道目录下的具体文件名称时,可以直接通过链接直接访问。
strahe
2015-12-18 10:42:43 +08:00
本身就支持的又不是什么特别的需求
neodreamer
2015-12-18 10:53:04 +08:00
@strahe 囧,发现了,自己犯了个严重错误,实际上 把 Options Indexes FollowSymLinks 改成 Options FollowSymLinks 就可以了。感谢楼上各位鼎力相助。
neodreamer
2015-12-18 10:57:42 +08:00
麻烦管理员把这个帖子移到 水节点下。

的确太水了。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/244386

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX