操作
将 Lighttpd 与 Coral Cache 结合使用¶
这份快速指南展示了如何在您的配置文件中添加内容以利用 Coral Cache。Coral Cache 是一个免费的内容分发网络,常用于应对被 dugg/slashdotted 的情况。
Coral Cache 基础知识¶
Coral Cache 易于使用。只需在任何域名的末尾添加“.nyud.net”(例如 http://www.google.com.nyud.net),其余的一切都会为您处理。当然,缓存意味着您缓存的任何内容都将变为静态。默认情况下,内容缓存 12 小时,这对于大多数用途来说可能没问题,特别是如果您只缓存图片。
配置文件示例¶
Coral Cache 通过从您的服务器请求内容来自动构建其缓存。因此,我们不能简单地重定向所有内容,我们必须实际响应来自 Coral Cache 的请求。Coral Cache 还具有某种容错能力……如果由于某种原因它无法处理请求,它会将请求发送回您的服务器。因此,我们必须对此进行测试。
您需要启用 mod_redirect
server.modules = ( "mod_redirect" )
现在,这是代码的核心部分(感谢 freenode#lighttpd 提供的提示)
# make sure this isn't CoralCache requesting content $HTTP["useragent"] !~ "^CoralWebPrx" { # make sure that this wasn't sent back to us from CoralCache $HTTP["querystring"] !~ "(^|&)coral-no-serve$" { url.redirect = ( "^/.*" => "http://www.example.com.nyud.net$0" ) } }
如果您想同时为多个主机名执行此操作,请尝试此方法
# make sure this isn't CoralCache requesting content $HTTP["useragent"] !~ "^CoralWebPrx" { # make sure that this wasn't sent back to us from CoralCache $HTTP["querystring"] !~ "(^|&)coral-no-serve$" { # capture hostname $HTTP["host"] =~ "^[^:]*" { url.redirect = ( "^/.*" => "http://%0.nyud.net$0" ) } } }