下面按常见场景给你一套在 Debian 上调试 Apache(通常是 apache2)的实用流程,从“看状态”到“看日志”再到“常见坑”。
systemctl status apache2
或
service apache2 status
启动 / 重启 / 停止:
sudo systemctl start apache2
sudo systemctl restart apache2
sudo systemctl stop apache2
这是最常见的错误来源。
sudo apache2ctl configtest
或
sudo apache2 -t
✅ 正常输出:
Syntax OK
❌ 错误会直接告诉你哪一行配置有问题。
sudo tail -f /var/log/apache2/error.log
sudo tail -f /var/log/apache2/access.log
如果站点有独立 VirtualHost,日志可能在:
/var/log/apache2/你的站点名-error.log
编辑:
sudo nano /etc/apache2/apache2.conf
修改:
LogLevel warn
为:
LogLevel debug
然后重启:
sudo systemctl restart apache2
ls /etc/apache2/sites-enabled/
sudo apache2ctl -S
会显示:
sudo ss -tulnp | grep apache
或
sudo netstat -tulnp | grep apache
常见端口:
sudo ufw status
确保:
sudo ufw allow 80
sudo ufw allow 443
例如 /var/www/html:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
Debian 一般不用 SELinux,用 AppArmor。
apache2ctl -M
启用模块示例:
sudo a2enmod rewrite
sudo a2enmod ssl
sudo systemctl restart apache2
sudo apache2ctl -S
openssl s_client -connect localhost:443
常见错误:
ssl 模块apache2ctl configtest 是否 OKerror.log 有无明显报错a2ensite)www-data如果你愿意,可以把:
error.log 报错内容贴出来,我可以直接帮你定位问题。