CentOS 上 Apache 缓存优化实用指南
一 核心思路与模块
二 配置步骤
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "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"
ExpiresByType text/css "access plus 30 days"
ExpiresByType application/javascript "access plus 30 days"
ExpiresByType text/html "access plus 1 hour"
ExpiresDefault "access plus 1 day"
</IfModule>
<IfModule mod_cache.c>
<IfModule mod_cache_disk.c>
CacheRoot "/var/cache/apache2/mod_cache_disk"
CacheEnable disk /
CacheDirLevels 2
CacheDirLength 1
CacheDefaultExpire 3600
CacheMaxExpire 86400
CacheIgnoreHeaders Set-Cookie
</IfModule>
</IfModule>
LoadModule file_cache_module modules/mod_file_cache.so
CacheFile /var/www/html/index.html
CacheFile /var/www/html/static/js/app.min.js
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript
</IfModule>
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
<IfModule mod_headers.c>
Header set Cache-Control "public, max-age=31536000" env=!no-cache
</IfModule>
三 验证与监控
四 进阶与注意事项