以下是CentOS Apache2性能调优的关键技巧:
MaxKeepAliveRequests
(如100)和KeepAliveTimeout
(如5秒)。worker
或event
模块(默认prefork
适合无线程安全模块场景),优化StartServers
、MaxRequestWorkers
等参数。mod_expires
设置缓存时间(如CSS/JS缓存30天)。mod_deflate
压缩文本类数据(如HTML/CSS/JS)。/etc/sysctl.conf
,优化TCP连接(如net.ipv4.tcp_tw_reuse=1
)、文件句柄数等。/etc/security/limits.conf
,提升nofile
值(如65535)。mod_rewrite
若未使用),减少资源占用。LogLevel warn
)。mod_proxy
和mod_cache
缓存后端响应,减轻服务器压力。mod_http2
提升多路复用性能(需客户端支持)。mod_proxy_balancer
分发请求到多个Apache实例。注意:修改配置后需重启Apache服务(systemctl restart httpd
),并使用top
、ab
等工具监控性能,确保优化效果。