Ubuntu 上 Apache2 宕机(停止响应 / 进程退出 / 无法访问) 是很常见的问题,原因通常集中在资源、配置、权限、依赖服务这几类。下面按「最常见 → 较少见」给你系统梳理,并告诉你怎么快速定位。
症状
systemctl status apache2 显示 failed 或 killed/var/log/syslog 中有:Out of memory: Killed process (apache2)
原因
MaxClients / MaxRequestWorkers 设置过大✅ 解决:
free -h
dmesg | grep -i oom
调整:
<IfModule mpm_prefork_module>
MaxRequestWorkers 50
MaxConnectionsPerChild 100
</IfModule>
症状
systemctl restart apache2 失败常见错误
✅ 排查:
sudo apache2ctl configtest
journalctl -xeu apache2
常见冲突
✅ 检查:
sudo netstat -tulnp | grep :80
sudo lsof -i :80
症状
原因
✅ 查看:
ps aux | grep apache2
tail -f /var/log/apache2/error.log
systemctl status apache2
journalctl -u apache2 --no-pager
可能原因:
systemctl stop 后未启动✅ 修复:
sudo systemctl enable apache2
sudo systemctl restart apache2
症状
✅ 检查:
df -h
du -sh /var/log/*
df -i
/var/www 不可读www-data 无权限✅ 修复示例:
sudo chown -R www-data:www-data /var/www
sudo chmod -R 755 /var/www
sudo aa-status
✅ 临时缓解:
Timeout 30
KeepAliveTimeout 5
# 1. 服务状态
systemctl status apache2
# 2. 错误日志
tail -n 100 /var/log/apache2/error.log
# 3. 系统日志
journalctl -u apache2
# 4. 资源
free -h
df -h
top
你可以直接发我:
systemctl status apache2 输出/var/log/apache2/error.log 最后 30 行我可以直接帮你判断是哪种宕机原因并给具体修复命令。