CentOS 上 Apache 加载缓慢通常不是单一原因,而是 系统资源、Apache 配置、网络、应用层 等多个因素叠加。下面按最常见 → 较少见的顺序给你一个系统性的排查思路。
Apache 默认会对客户端 IP 做 反向 DNS 解析。
现象
Hostname 解析慢解决
# httpd.conf
HostnameLookups Off
✅ 强烈建议关闭
CentOS 默认可能使用 prefork(老、慢、吃内存)
查看当前 MPM
httpd -V | grep MPM
推荐配置(prefork 示例)
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 1000
</IfModule>
如果是 高并发站点,建议:
event 或 workerphp-fpm如果是 PHP 应用(WordPress / Laravel / 自研系统)
排查
top
htop
常见原因
opcache解决
yum install php-opcache
php.ini:
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
现象
建议配置
KeepAlive On
KeepAliveTimeout 5
MaxKeepAliveRequests 100
free -h
vmstat 1
表现
解决
MaxRequestWorkersiostat -x 1
表现
%iowait 很高常见原因
建议
Protocols h2 http/1.1
现象
检查
优化示例
SSLEngine on
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite HIGH:!aNULL:!MD5
tail -f /var/log/httpd/access_log
tail -f /var/log/httpd/error_log
✅ 执行以下命令:
free -h
top
iostat -x 1
httpd -V | grep MPM
✅ 检查:
你可以直接贴出:
httpd -V 输出free -h 和 top 截图我可以 直接给你一份最优 Apache 配置方案 ✅