在 Ubuntu 上 Apache 加载缓慢 的原因有很多,下面按常见程度给你一个系统排查清单,你可以逐条对照。
Apache 在记录日志或做 HostnameLookups 时会尝试反向解析客户端 IP。
检查:
grep HostnameLookups /etc/apache2/apache2.conf
解决:
HostnameLookups Off
重启:
sudo systemctl restart apache2
Apache 启动时会尝试解析主机名。
现象:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name
解决:
sudo nano /etc/apache2/conf-available/servername.conf
写入:
ServerName localhost
启用并重启:
sudo a2enconf servername
sudo systemctl restart apache2
如果是 PHP 网站:
opcache 未开启检查 PHP 模块:
php -m
开启 OPCache(强烈推荐):
sudo phpenmod opcache
sudo systemctl restart apache2
测试:
mysql -h localhost -u user -p
Apache 监听 IPv6,但网络不支持,导致超时。
检查:
sudo netstat -tulnp | grep apache
修改监听:
Listen 0.0.0.0:80
Ubuntu 一般是 ufw:
sudo ufw status
top
iostat -x 1
free -h
apache2ctl -M
可禁用不用的:
sudo a2dismod status
sudo systemctl restart apache2
每次请求都解析 .htaccess
建议:
VirtualHost 中.htaccessAllowOverride None
sudo apache2ctl -S
sudo apache2ctl configtest
systemctl status apache2
journalctl -u apache2
我可以直接帮你改配置。