以下是CentOS中优化Apache性能的关键措施:
KeepAlive On
,合理配置MaxKeepAliveRequests
(如100)和KeepAliveTimeout
(如5秒)。prefork
(静态内容)或worker
/event
(动态内容),修改StartServers
、MaxRequestWorkers
等参数。mod_expires
设置缓存时间(如图片、CSS缓存1年)。mod_deflate
压缩文本类数据(如HTML/CSS/JS),减少传输量。mod_http2
(提升传输效率)、mod_ssl
(SSL加速)。mod_rewrite
(若无需URL重写)。net.ipv4.tcp_tw_reuse
、vm.swappiness
等,提升网络和内存效率。ServerSignature Off
和ServerTokens Prod
,降低攻击风险。logrotate
定期轮询日志,避免磁盘占用过高。top
、htop
、sar
等工具实时监控资源使用情况。操作前建议:备份配置文件,测试环境验证后再应用到生产环境。
参考来源:[1,2,3,4,5,6,7,8,9,10,11]