大网数据广告活动
服务器运维问答

Restrict access to apache document root but not for subdomains

· 52CE 我爱测

I'm running Apache on CentOS 7. I have configured multiple virtual hosts. Their root directories are in /var/www/html/{example.com, sub1.example.com, etc.} . I have also configured a 000-default.conf vhost to redirect all incomin…

问题原文

原帖链接 · LuMa · CC BY-SA 3.0

I'm running Apache on CentOS 7. I have configured multiple virtual hosts. Their root directories are in /var/www/html/{example.com, sub1.example.com, etc.}. I have also configured a 000-default.conf vhost to redirect all incoming traffic (which is not covered by one of the virtual hosts) to the main document root (/var/www/html) and show a blank page.

But know I face a critical security issue: If a visitor is redirected into the document root with the blank index.html file, he can append the URL with "/example.com" and visit this directory. This might not seem dangerous, but imagine if for example a Laravel application is installed there, which has it's one public folder (/var/www/html/example.com/public). Then a visitor would be able to browse the laravel directory with all it's configuration files!

How can I prevent this?

已采纳解答

原帖链接 · Diamond · CC BY-SA 3.0

You can prevent directory listings using the following apache directives:

Options -Indexes

You can set this globally in httpd.conf, for a particular directory using the <Directory </Directory> block as below or using .htaccess file inside the directory.

<Directory /var/www/html/example.com/public>
  Options -Indexes
</Directory>

For further reference: Directory Listing Configuration

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。