温馨提示×

怎样排查debian apache故障

小樊
32
2026-10-06 11:23:39
栏目: 智能运维

在 Debian 上排查 Apache(通常是 apache2)故障,可以按下面“由浅入深”的思路一步步来。


一、确认 Apache 是否在运行

systemctl status apache2

常见状态:

  • active (running):服务正常
  • failed:启动失败(看日志)
  • inactive:没启动

尝试启动 / 重启:

sudo systemctl start apache2
sudo systemctl restart apache2

如果启动失败,直接进入第二步。


二、查看 Apache 错误日志(最关键)

Debian 默认路径:

/var/log/apache2/error.log

实时查看:

tail -f /var/log/apache2/error.log

常见错误示例:

  • Address already in use → 端口被占用
  • Permission denied → 文件/目录权限问题
  • Invalid command → 配置语法错误
  • DocumentRoot does not exist → 站点目录不存在

三、检查 Apache 配置语法

sudo apache2ctl configtest

或:

sudo apache2 -t

输出:

  • Syntax OK → 配置没问题
  • 有错误 → 按提示修改对应文件

配置文件位置:

/etc/apache2/apache2.conf
/etc/apache2/sites-enabled/
/etc/apache2/mods-enabled/

四、检查端口与防火墙

1. 看端口是否监听

sudo ss -tlnp | grep :80
sudo ss -tlnp | grep :443

如果没有监听:

  • Apache 没启动
  • 监听地址配置错误

2. 防火墙(如有)

sudo ufw status

允许 HTTP/HTTPS:

sudo ufw allow 80
sudo ufw allow 443

五、检查虚拟主机配置

列出已启用站点:

ls /etc/apache2/sites-enabled/

查看对应配置:

cat /etc/apache2/sites-enabled/000-default.conf

重点检查:

  • ServerName
  • DocumentRoot
  • <Directory> 权限
  • 是否启用了 ServerAlias

启用/禁用站点:

sudo a2ensite xxx.conf
sudo a2dissite xxx.conf

六、检查模块是否启用

例如 PHP、SSL:

ls /etc/apache2/mods-enabled/

启用模块:

sudo a2enmod ssl
sudo a2enmod php8.2

重启 Apache:

sudo systemctl restart apache2

七、权限与 SELinux(Debian 一般不用 SELinux)

Debian 默认用权限 + www-data 用户:

ps aux | grep apache

网站目录权限示例:

sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html

八、HTTPS / SSL 故障

检查 SSL 模块:

sudo a2enmod ssl

检查证书路径是否正确:

SSLCertificateFile
SSLCertificateKeyFile

测试:

openssl s_client -connect localhost:443

九、快速排查清单(速查)

✅ Apache 是否运行
✅ error.log 有没有报错
✅ configtest 是否 OK
✅ 端口是否监听
✅ 防火墙是否放行
✅ 虚拟主机是否正确
✅ 文件权限是否正确
✅ 模块是否启用


如果你愿意,可以把 具体报错信息(如 error.log 内容或 systemctl status 输出)贴出来,我可以直接帮你定位问题。

0 踩