优化Apache2启动速度可从以下方面入手:
a2dismod
命令禁用不需要的模块(如mod_rewrite
若未使用),减少资源占用。prefork
(适合非线程安全场景)或worker/event
(适合高并发场景),并调整相关参数(如MaxRequestWorkers
、ThreadsPerChild
)。KeepAlive On
,并合理设置MaxKeepAliveRequests
(如100)和KeepAliveTimeout
(如5秒),减少连接建立开销。mod_cache
和mod_expires
缓存静态资源,减少重复请求处理时间。warn
或error
,减少非必要日志输出,降低磁盘I/O。MaxClients
(或ServerLimit
)设置合理并发上限,避免资源耗尽。net.ipv4.tcp_tw_reuse=1
)优化TCP连接复用。修改配置后需重启Apache服务生效:sudo systemctl restart apache2
。建议先在测试环境验证优化效果。