在 Ubuntu 的 Apache2 中,“禁止目录”通常有以下几种常见需求,你可以根据具体情况选择:
默认情况下,如果目录下没有 index.html 等文件,Apache 可能会列出文件。
编辑站点配置,例如:
sudo nano /etc/apache2/sites-available/000-default.conf
在 <VirtualHost> 或 <Directory> 中加入:
<Directory /var/www/html>
Options -Indexes
</Directory>
保存后重启 Apache:
sudo systemctl restart apache2
在目标目录下创建 .htaccess 文件:
nano /var/www/html/.htaccess
写入:
Options -Indexes
确保 Apache 允许 .htaccess:
AllowOverride All
<Directory> 或 .htaccess<Directory /var/www/html/private>
Require all denied
</Directory>
在 /var/www/html/private/.htaccess 中写:
Require all denied
例如禁止访问 .inc 文件:
<Files ~ "\.inc$">
Require all denied
</Files>
<Location /admin>
Require all denied
</Location>
sudo apache2ctl configtest
如果你能说明是:
我可以给你更精确的配置示例。