--test file by blueant --ngx.say('user ip = ' .. ngx.var.remote_addr .. '
'); --ngx.say('the length of ip2zone = ' .. tostring(ip2zone.len()) .. '
'); mip = ngx.var.remote_addr; if ngx.var.http_addr ~= nil then mip = ngx.var.http_addr end --ngx.say('mip = ' .. mip .. '
'); bin = tool.ip2bin(mip); zone = base.search_zone(ip2zone, bin); --ngx.say('this ip ' .. mip .. ' is user of the ' .. tostring(zone) .. '
'); snode = base.search_percent_node(isp2node, zone); --ngx.say('snode = ' .. snode .. '
'); --ngx.say('this ip ' .. mip .. ' is disp to ' .. tostring(snode) .. '
'); --ngx.say('the ip ' .. mip .. ' is disp to the ' .. snode .. '
'); uri = ngx.var.request_uri; mstart, mend = string.find(uri, '?'); if mstart ~= nil then uri = string.sub(uri, 1, mstart - 1); end nstart, nend = string.find(uri, '/', 1); rp = dbase.rfind(uri, '/'); if rp ~= nil then file = string.sub(uri, rp + 1); fp = dbase.rfind(file, '.'); if fp ~= nil then key = string.sub(file, 1, fp - 1); else key = 'index'; end else key = 'index'; end point = ring.str2point(key); --ngx.say('c so ' .. test .. ' = ' .. tostring(point) .. '
'); --ngx.say('the point is ' .. point .. '
'); --ngx.say('singles length = ' .. singles.len() .. '
'); if snode == specnode then httphost = ngx.var.http_host; istart, iend = string.find(httphost, ':'); if istart ~= nil then httphost = string.sub(httphost, 1, istart - 1); end --ngx.say('httphost = ' .. httphost .. '
'); todomain = dom2node.get(httphost); if todomain == nil then todomain = dom2node.get('default'); snode = todomain; else snode = todomain; end end --ngx.say('snode = ' .. snode .. '
'); --ngx.say('uri = ' .. ngx.var.request_uri .. '
'); new_http_host = tostring(ring.findhost(point, points, flags, singles, loops, rings, snode)); --ngx.say('' .. new_http_host .. '
'); if ngx.var.server_port ~= '80' then new_location = 'http://' .. new_http_host .. ':' .. ngx.var.server_port .. ngx.var.request_uri; else new_location = 'http://' .. new_http_host .. ngx.var.request_uri; end --new_http_host = 'ngx.org'; --ngx.say('the ip ' .. mip .. ' is disp to the ' .. new_location .. '
'); return ngx.redirect(new_location);