以下是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
。