Web 加速缓存¶
模块: mod_cache
描述¶
mod_cache 站点于 2008 年 2 月 29 日重新上线
mod_cache 为 mod_proxy 提供一个共享的 Web 缓存,并使用类似于 Squid Cache 的配置。mod_cache 具有以下几个主要优点:
- 简单:mod_cache 在请求处理阶段之间设置 lighttpd 标志。然后,请求由 mod_staticfile、mod_proxy 或其他模块处理。
- 健壮:mod_cache 将缓存存储到文件系统而非内存中,以避免内存泄漏/耗尽。
- 快速:Lighttpd 使用 Sendfile 系统调用,它直接将文件写入网络接口。
- 强大:mod_cache 可以与 Lighttpd 的其他插件(mod_deflate 和 mod_secdownload 除外)结合使用。例如:使用 mod_compress 压缩缓存文件,使用 mod_access/mod_trigger_b4_dl 实现防盗链限制,或使用 mod_flv_streaming 进行原生 flv 文件流传输。
通过共享 Web 缓存,mod_proxy 能够从本地缓存中提供内容,而无需重新下载大文件,从而在提高用户体验速度的同时,减少了服务器上游的带宽消耗。
这并非旨在用作反向代理,因为反向代理在 Lighttpd 中很少有用,Lighttpd 的设计目标是通过仅在需要时加载外部应用程序(例如 FastCGI)并优雅地处理慢速用户传输而不阻塞,以最小的资源使用处理大量并发请求。有关优化 Lighttpd 性能的更多信息,请参阅:http://trac.lighttpd.net/trac/wiki/Docs:Performance
安装¶
此模块是第三方模块,不包含在官方发行版中。您可以从此处下载补丁程序:
- 对于 lighttpd 1.4.13:
http://www.linux.com.cn/modcache/lighttpd-1.4.13.mod_cache.v1.2.patch - 对于 lighttpd 1.4.18:
http://www.linux.com.cn/modcache/lighttpd-1.4.18.modcache.v.1.4.3.patch - 对于 lighttpd 1.4.19:
http://www.linux.com.cn/modcache/lighttpd-1.4.19.modcache.v.1.6.0.patch
或者您可以下载以下打过补丁的 lighttpd 版本:
构建 mod_cache 需要 PCRE 库。
在尝试安装此模块或任何其他第三方模块之前,请务必检查更新。
如果官方源不可用,有一个专门的 mod_cache Google 群组:http://groups.google.com/group/mod_cache
选项¶
请参阅 [http://code.google.com/p/lighttpd-improved/]
cache.bases
希望保存缓存文件的目录数组。
例如:
cache.bases=("/data/cache", "/data2/cache")
Default: not set
cache.enable
启用或禁用 mod_cache。
例如:
cache.enable = "disable" $HTTP["host"] == "video.example.org" { cache.enable = "enable" }
Default: enable
cache.domains
mod_cache 将缓存的域名 PCRE 正则表达式数组。
例如:
cache.domains = ("mydomain.com$")
Default: not set (all domains are cached)
cache.support-queries
是否忽略请求 URL 中的 '?'。
例如:
cache.support-queries = "enable" # mod_cache 将 "/uri?q1" 或 "/uri?q2" 视为 "/uri"。*
Default: disable.
cache.debug
是否将 mod_cache 调试消息写入 error.log
默认:禁用。
cache.purge-host
允许清除缓存文件的 PCRE 正则表达式主机 IP
例如:
cache.purge-host = "^(192\.168\.|222\.120\.35\.)" # Allow PURGE from 192.168/16 and 222.120.35/24, plus hardcoded 10/8 and 127.0.0.1默认:未设置(10/8 和 127.0.0.1 硬编码到允许清除的 IP 列表中)
cache.ignore-hostname
不在缓存保存文件名中包含主机名
默认:禁用。
cache.refresh-pattern
“url_pcre_regex” => “分钟 选项”的数组。零分钟表示永远缓存。允许多个选项。
refresh-pattern 选项包括:
选项 | 描述 |
---|---|
ignore-reload | 当浏览器发送 'Cache-Control: no-cache' 头时,不更新缓存 |
update-on-refresh | 当浏览器发送 'Cache-Control: no-cache' 头时,更新缓存 |
override-expire | 在决定是否缓存时,忽略后端 'Expire' 头 |
ignore-cache-control-header | 在决定是否缓存时,忽略后端 'Cache-Control' 头 |
no-expire-header | 不为匹配的 URI 设置 expires 头。如果没有此选项,mod_cache 将根据 refresh-pattern 规则设置 expires 头 |
fetchall-for-range-request | 如果浏览器发送 'Range: xxx-yyybytes' 头,下载文件的所有内容。这对于多线程下载器(如 flashget)很有用 |
flv-streaming | 与 mod_flv_streaming 配合使用 |
nocache | 不缓存匹配的 URL |
示例