在 Ubuntu 上用 Apache 访问慢,原因通常可以分为 网络/客户端问题、系统资源问题、Apache 配置问题、应用/代码问题 几类。下面按常见程度给你一个排查清单。
在客户端测:
time curl -I http://你的IP/
ping 你的服务器IP
traceroute 你的IP
Apache 默认会做反向 DNS 或 HostnameLookups
HostnameLookups Off
✅ 修改后重启:
sudo systemctl restart 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
默认 mpm_prefork 容易堵:
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
或优化:
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 3000
</IfModule>
查看:
apache2ctl -M
可关闭:
sudo a2dismod status
sudo a2dismod autoindex
如果是 PHP:
file_get_contents() 网络请求排查:
sudo tail -f /var/log/apache2/access.log
sudo tail -f /var/log/apache2/error.log
top
htop
free -h
iostat -x 1
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
ufw 规则过多mod_security 太严格可临时测试:
curl -k https://IP
systemctl status apache2
journalctl -u apache2
apache2ctl -S
apache2ctl -M
你可以补充:
我可以直接帮你定位到具体配置 ✅