在 Ubuntu 的 Apache2 中,**禁止目录浏览(目录列表)**通常通过修改 Apache 配置或 .htaccess 来实现。
sudo nano /etc/apache2/sites-available/000-default.conf
(或你实际的虚拟主机配置文件)
<Directory> 块中添加或修改:<Directory /var/www/html>
Options -Indexes
</Directory>
sudo systemctl restart apache2
如果你的网站目录允许使用 .htaccess:
.htaccess:nano /var/www/html/.htaccess
Options -Indexes
.htaccess 生效AllowOverride All
sudo systemctl restart apache2
sudo nano /etc/apache2/apache2.conf
找到类似:
<Directory /var/www/>
Options Indexes FollowSymLinks
改为:
Options -Indexes FollowSymLinks
然后重启 Apache。
访问一个没有 index.html / index.php 的目录,如果看到:
Forbidden
You don't have permission to access this resource.
说明目录浏览已成功禁止 ✅
如果你愿意,我可以帮你检查具体的 Apache 配置文件内容。