15. require "apache2"
rewriteのような処理
function uri2file(r)
if string.match(r.uri, ".*¥.php") then
r.filename = "/usr/local/apache2.4/htdocs/".. r.hostname .."/".. r.uri
end
return apache2.DECLINED
end
夜の19時から24時は
function golden_balancer(r) サーバ分散する処理
ctime = os.date("%H")
if ctime > 19 then
if math.random() < 0.5 then
r.headers_out["Location"] = "http://server2.example.com/".. r.uri
return apache2.HTTP_MOVED_TEMPORARILY
end
else
return apache2.DECLINED
end
end
16. require "apache2"
load_limit = 2
LoadAvgを取得
function get_load()
file = io.open('/proc/loadavg', 'r')
state = file:read('*a')
file:close()
cload = string.match(state, '(%d+¥.%d+)%s+.*')
return cload
end
function load_checker(r)
if string.match(r.filename, "^.*¥.php$") then
LoadAvgを比較
cload = tonumber(get_load())
if cload > load_limit then
r:warn(r.filename .. “is CGI. current load(”.. cload ..“) is highter than load_limit(".. load_limi
r:puts("Sorry. loadavg high!")
return 503
else
r:debug(r.filename .. "is CGI. current load(".. cload ..") is lower than load_limit(".. load_lim
end
end
return apache2.OK
end 900行が30行くらいに