在 Debian 上用 Apache 出现 403 Forbidden,本质原因只有一个:Apache 被拒绝访问你请求的资源。但具体触发场景很多,下面按「最常见 → 较少见」帮你系统排查。
Apache 运行用户通常是 www-data
ps aux | grep apache
目录必须至少:
755644修复示例:
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www
⚠️ 注意:
+x)/home/xxx 直接放网站容易 403请求目录但没找到 index.html
报错类似:
Directory index forbidden by Options
解决:
<Directory /var/www/html>
Options Indexes FollowSymLinks
DirectoryIndex index.html index.php
</Directory>
或放一个 index.html
Debian 默认配置:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
如果你网站目录没单独放开,就会 403
✅ 正确示例:
<Directory /var/www/html>
Require all granted
</Directory>
修改后:
apache2ctl configtest
systemctl reload apache2
DocumentRoot /var/www/html
但实际目录是 /srv/www
a2ensite your-site.conf
systemctl reload apache2
确认:
apache2ctl -S
aa-status
可临时测试:
systemctl stop apparmor
⚠️ 不建议长期关闭
AllowOverride None
但用了 .htaccess
或 .htaccess 里有:
Require all denied
php-fpm 没运行Options -FollowSymLinks
但用了软链接
tail -n 50 /var/log/apache2/error.log
通常会直接写明原因,例如:
client denied by server configurationPermission denied: /var/www/htmlDirectory index forbidden<VirtualHost *:80>
DocumentRoot /var/www/html
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
如果你愿意,可以把:
发出来,我可以直接帮你定位是哪一条。