以下是Ubuntu LAMP中Apache的优化方法:
a2dismod/a2enmod命令切换。MaxRequestWorkers:根据内存设置最大并发进程数(如MaxRequestWorkers 150)。KeepAlive:启用以减少连接开销,KeepAliveTimeout设为3-5秒,MaxKeepAliveRequests设为50-100。mod_deflate:压缩文本类文件(HTML/CSS/JS),降低传输体积。sudo a2enmod deflate
sudo nano /etc/apache2/apache2.conf
# 添加:AddOutputFilterByType DEFLATE text/html text/css text/javascript
mod_expires:设置静态文件过期时间,减少重复请求。a2dismod关闭不使用的模块(如status、info),减少资源占用。mod_http2)。MaxClients/ServerLimit控制最大并发连接数,避免服务器过载。修改配置后需重启Apache:sudo systemctl restart apache2。