Apache2网站速度优化实操指南
一 核心网络与连接优化
二 选择并调优 MPM 多处理模块
sudo a2dismod mpm_preforksudo a2enmod mpm_eventsudo systemctl restart apache2三 启用压缩与静态资源缓存
sudo a2enmod deflate(Ubuntu/Debian)<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css \
application/javascript application/x-javascript application/json image/svg+xml
DeflateCompressionLevel 6
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|zip|gz|bz2)$ no-gzip dont-vary
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresDefault "access plus 60 seconds"
</IfModule>
<IfModule mod_cache.c>
<IfModule mod_cache_disk.c>
CacheRoot "/var/cache/apache2/mod_cache_disk"
CacheEnable disk /
CacheDirLevels 2
CacheDirLength 1
CacheIgnoreHeaders Set-Cookie
CacheIgnoreNoLastMod On
CacheDefaultExpire 3600
</IfModule>
</IfModule>
四 静态资源交付与内容优化
五 变更验证与运维建议
sudo apachectl configtest、sudo systemctl reload apache2(或 graceful)。