在Ubuntu上提高Apache并发量可从配置优化、模块选择、系统调优等方面入手,具体如下:
mpm_worker或mpm_event模块(线程模型,资源占用更少),需禁用mpm_prefork:sudo a2dismod mpm_prefork && sudo a2enmod mpm_worker/event && sudo systemctl restart apache2
MaxClients):控制最大并发请求数,需根据服务器内存调整(建议每进程/线程约占用20-30MB内存)。KeepAliveTimeout 5(秒)避免连接占用过久。mod_cache和mod_expires模块,减少后端请求压力。mod_deflate压缩响应数据,降低传输时间。/etc/security/limits.conf,设置nofile为65535或更高。/etc/sysctl.conf,增加net.core.somaxconn和net.ipv4.tcp_max_syn_backlog以提升连接队列长度。htop、apachetop等工具监控服务器负载,分析日志定位瓶颈。示例配置(event MPM):
<IfModule mpm_event_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 200
MaxConnectionsPerChild 0
</IfModule>
修改后需重启Apache生效:sudo systemctl restart apache2。