是否可以设置“connection.kbytes-per-second”取决于Lighttpd中一天中的小时?
如在晚上7点到11点之间将其限制为250kb / s,凌晨1点至凌晨5点限制为500kb / s等?
谢谢!
答案 0 :(得分:1)
抱歉延迟,我的回答 - lua脚本:
-- If we don't find our "superSecretString" in the request uri, then
if string.find(lighty.env["request.uri"], "superSecretString") == nil then
local hour = os.date("%H")
-- Account for whether or not there are already query variables
if string.find(lighty.env["request.uri"], "?") == nil then
lighty.env["request.uri"] = lighty.env["request.uri"] .. "?superSecretString=" .. hour
else
lighty.env["request.uri"] = lighty.env["request.uri"] .. "&superSecretString=" .. hour
end
-- Restart the request, the script will run again, but return nil.
return lighty.RESTART_REQUEST
end
-- Continue request, the above if already would have ran.
return nil
和配置文件:
server.modules( ..., mod_magnet, ...)
# Match hours 00 through 19
$HTTP["querystring"] =~ ".*superSecretString=[0,1][0-9]" {
connection.kbytes-per-second = 200
}
# Match 20 through 23
$HTTP["querystring"] =~ ".*superSecretString=2[0-3]" {
connection.kbytes-per-second = 100
}
magnet.attract-raw-url-to = ( "<path to lua script file>" )
如果不明显,如果有人知道你的“superSecretString”,他们就可以将其短路,但它永远不会离开服务器。
我觉得应该可以从lua脚本中设置连接速度,但我无法弄清楚如何。
希望这有帮助。