-- 指定模块引用目录,否则无法加载同目录下的其他文件 --package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua'; package.path = package.path .. ';/?.lua'; local url_parser = require "net.url" local _M = {} function _M.host(s) return (s.."/"):match("://(.-)/") end function _M.upt(url) local uri = url_parser.parse(url) local hostname = uri.host local pathname = uri.path ngx.log(ngx.INFO, 'hostname...' .. hostname .. ' path...' .. pathname) local secret; if string.find(hostname, "moicen.com") then ngx.log(ngx.INFO, 'match moicen.com: ' .. ngx.var.upt_moicen_secret) secret = ngx.var.upt_moicen_secret elseif string.find(hostname, "alchemy-studio.cn", 1, true) then ngx.log(ngx.INFO, 'match alchemy: ' .. ngx.var.upt_alchemy_secret) secret = ngx.var.upt_alchemy_secret elseif string.find(hostname, "huiwings.cn") then ngx.log(ngx.INFO, 'match huiwings.cn: ' .. ngx.var.upt_huiwings_secret) secret = ngx.var.upt_huiwings_secret else ngx.status = 401 ngx.log(ngx.ERR, "Reject URL -> ", hostname) ngx.exit(ngx.status) end ngx.log(ngx.INFO, 'secret...' .. secret) local duration = ngx.var.upt_duration local etime = os.time() + duration local sign = ngx.md5(secret .. '&' .. etime .. '&' .. pathname) ngx.log(ngx.INFO, 'sign...' .. sign .. ' etime..' .. etime) local upt = string.sub(sign, 13, 13 + 7) .. etime ngx.log(ngx.INFO, 'upt...' .. upt) return (upt) end return _M