Ubuntu 上 Apache 访问缓慢的原因有很多,下面按常见程度给你一个排查清单,你可以逐条对照。
top
htop
free -h
✅ 解决:
查看当前 MPM:
apachectl -V | grep MPM
常见情况:
prefork:吃内存,并发稍高就慢worker / event:更适合高并发✅ 建议:
eventphp-fpm + event/etc/apache2/mods-enabled/mpm_prefork.conf
示例(prefork):
StartServers 5
MaxClients 150
并发超过上限就会排队。
apachectl -M | grep php
如果有 php7_module → 性能较差
✅ 建议:
php-fpm + proxy_fcgisudo apt install php-xdebug
或:
EXPLAIN 分析 SQLHostnameLookups Off
(在 apache2.conf 中)
cat /etc/hosts
确保:
127.0.0.1 localhost
iostat -x 1
✅ 解决:
a2enmod http2
✅ 解决:
top
free -h
apachectl -V | grep MPM
apachectl -M | grep php
cat /etc/hosts
你可以补充:
我可以直接给你针对性优化配置。