首先在httpd.conf里面,开启缓存的相关模块。

然后配置如下几个参数即可

CacheRoot "xxx"
CacheEnable disk xxx
CacheDirLevels 5
CacheDirLength 4
CacheMinFileSize 10
CacheMaxFileSize 4000000
其中CacheRoot要确保Apache运行的用户有权限??梢孕炊喔?CacheEnable disk xxx来自定义缓存配置。
部分参数意义如下:
CacheRoot 指令
描述: | 存储缓存 files 的目录根目录 |
句法: | CacheRoot directory |
Context: | server config,virtual host |
状态: | 延期 |
??椋?/td> | mod_cache_disk |
CacheRoot
指令定义磁盘上包含 cache files 的目录的 name。如果已将mod_cache_disk??榧釉鼗虮嘁氲?Apache 服务器,则必须定义此指令。未能为CacheRoot
提供 value 将导致 configuration 文件处理错误。 CacheDirLevels和CacheDirLength指令定义指定根目录下的目录结构。
CacheDirLevels 指令
描述: | 缓存中子目录的级别数。 |
句法: | CacheDirLevels levels |
默认: | CacheDirLevels 2 |
Context: | server config,virtual host |
状态: | 延期 |
??椋?/td> | mod_cache_disk |
CacheDirLevels
指令设置缓存中的子目录级别数?;捍娴氖萁4嬖贑acheRoot目录下的许多目录级别。
CacheDirLevels
的高值与CacheDirLength
的低值相结合将导致相对较深的层次结构,每个 level 都有少量子目录。
CacheDirLevels
?* CacheDirLength的结果不得高于 20。
CacheDirLength 指令
描述: | 子目录名称中的字符数 |
句法: | CacheDirLength length |
默认: | CacheDirLength 2 |
Context: | server config,virtual host |
状态: | 延期 |
??椋?/td> | mod_cache_disk |
CacheDirLength
指令设置缓存层次结构中每个子目录 name 的字符数。它可以与CacheDirLevels
结合使用,以确定缓存层次结构的近似结构。
CacheDirLength
的高值与CacheDirLevels
的低值相结合将导致相对平坦的层次结构,每个 level 都有大量子目录。
CacheDirLevels *?CacheDirLength
的结果不得高于 20。
另外也可以使用 mod_expires 模块的Expire/Cache-Control头来控制,同样首先需要删除掉配置文件前面的#,开启这个模块。

A7200000代表文件缓存7200000/3600/24=83天
<IfModule expires_module>
ExpiresActive on
ExpiresByType text/css A7200000
ExpiresByType text/min.css A7200000
ExpiresByType text/x-component A7200000
ExpiresByType image/jpeg A7200000
ExpiresByType image/gif A7200000
ExpiresByType image/png A7200000
ExpiresByType image/bmp A7200000
ExpiresByType image/x-icon A7200000
ExpiresByType image/svg+xml A7200000
ExpiresByType audio/ogg A7200000
ExpiresByType video/mp4 A7200000
ExpiresByType video/ogg A7200000
ExpiresByType video/webm A7200000
ExpiresByType video/x-flv A7200000
ExpiresByType application/json A7200000
ExpiresByType application/xml A7200000
ExpiresByType application/pdf A7200000
ExpiresByType application/javascript A7200000
ExpiresByType application/x-javascript A7200000
ExpiresByType application/x-font-ttf A7200000
ExpiresByType application/font-woff A7200000
ExpiresByType application/font-woff2 A7200000
ExpiresByType application/x-shockwave-flash A7200000
</IfModule>
<FilesMatch "\.(ico|pdf|flv|mp4|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 1 year"
</FilesMatch>