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

Apache httpd 2.4 反向代理 开启缓存

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

Apache httpd 2.4 反向代理 开启缓存
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
状态:延期
模块: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
状态:延期
模块:mod_cache_disk

CacheDirLevels指令设置缓存中的子目录级别数。缓存的数据将保存在CacheRoot目录下的许多目录级别。

CacheDirLevels的高值与CacheDirLength的低值相结合将导致相对较深的层次结构,每个 level 都有少量子目录。

CacheDirLevels * CacheDirLength的结果不得高于 20。

CacheDirLength 指令

描述:子目录名称中的字符数
句法:CacheDirLength length
默认:CacheDirLength 2
Context:server config,virtual host
状态:延期
模块:mod_cache_disk

CacheDirLength指令设置缓存层次结构中每个子目录 name 的字符数。它可以与CacheDirLevels结合使用,以确定缓存层次结构的近似结构。

CacheDirLength的高值与CacheDirLevels的低值相结合将导致相对平坦的层次结构,每个 level 都有大量子目录。

CacheDirLevels * CacheDirLength的结果不得高于 20。

另外也可以使用 mod_expires 模块的Expire/Cache-Control头来控制,同样首先需要删除掉配置文件前面的#,开启这个模块。

Apache httpd 2.4 反向代理 开启缓存

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>

相关文章

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

联系电话

176-8951-1878

微信
微信
分享本页
返回顶部
西藏巨腾信息技术有限公司提供拉萨网站建设、软件开发、小程序开发、APP开发、网络营销、在线推广、在线商城开发等服务,联系电话: 17689511878