优化Apache服务器配置可从以下方面入手:
MaxClients
/MaxRequestWorkers
(建议不超过服务器内存能承载的进程数)。MinSpareServers
/MaxSpareServers
(控制空闲进程数量,避免频繁创建/销毁)。KeepAlive
并设置合理KeepAliveTimeout
(减少TCP握手开销,建议5-15秒)。mod_cache
缓存静态内容,搭配mod_expires
设置静态资源缓存时间。mod_deflate
或mod_brotli
压缩响应数据(Brotli压缩率更高)。StartServers
、MaxRequestWorkers
,避免进程过多占用内存。ThreadsPerChild
、MaxRequestWorkers
,提升线程利用率。mod_autoindex
等)。MaxRequestsPerChild
(避免进程内存泄漏,建议设置为非0值)。net.core.somaxconn
、tcp_tw_reuse
)提升网络性能。mod_status
、top
等工具监控服务器状态,根据负载调整参数。修改配置后需通过apachectl configtest
测试语法正确性,并重启服务生效。