本文共 3022 字,大约阅读时间需要 10 分钟。
OpenResty ????? Nginx ? Lua ??? Web ?????? Nginx ????? Lua ???????? Web ???????? OpenResty ?????????
??????????????????
yum install readline-devel pcre-devel openssl-devel
sudo apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl
OpenResty ?? LuaJit ??? Lua ??????????????
cd /tmp/git clone http://luajit.org/git/luajit-2.0.gitcd luajit-2.0/make && make install
ln -sf /usr/local/bin/luajitln -sf /usr/local/lib/libluajit-5.1.so.2 /usr/lib/
?? OpenResty ??????
cd /tmp/wget http://agentzh.org/misc/nginx/ngx_openresty-1.2.4.13.tar.gztar xzf ngx_openresty-1.2.4.13.tar.gz
cd ngx_openresty-1.2.4.13/./configure --prefix=/usr/local/openresty --with-luajitmake && make install
? OpenResty ??? Nginx?
http { lua_shared_dict limit 10m; lua_shared_dict jsjump 10m; server { listen 80; server_name www.centos.bz; location / { default_type text/html; content_by_lua_file "/usr/local/openresty/nginx/conf/lua"; } location @cc { internal; root html; index index.html index.htm; } }} local ip = ngx.var.binary_remote_addrlocal limit = ngx.shared.limitlocal req, _ = limit:get(ip)if req then if req > 20 then ngx.exit(503) else limit:incr(ip, 1) endelse limit:set(ip, 1, 10)endlocal jsjump = ngx.shared.jsjumplocal uri = ngx.var.request_urilocal jspara, flags = jsjump:get(ip)local args = ngx.req.get_uri_args()if jspara then if flags then ngx.exec("@cc") else local p_jskey = '' if args["jskey"] and type(args["jskey"]) == 'table' then p_jskey = args["jskey"][table.getn(args["jskey"])] else p_jskey = args["jskey"] end if p_jskey and p_jskey == tostring(jspara) then jsjump:set(ip, jspara, 3600, 1) ngx.exec("@cc") else local url = '' if ngx.var.args then url = ngx.var.scheme .. "://" .. ngx.var.host .. uri .. "&jskey=" .. jspara else url = ngx.var.scheme .. "://" .. ngx.var.host .. uri .. "?jskey=" .. jspara end local jscode = "window.location.href='" .. url .. ';'" ngx.say(jscode) end endelse math.randomseed(os.time()) local random = math.random(100000, 999999) jsjump:set(ip, random, 60) local url = '' if ngx.var.args then url = ngx.var.scheme .. "://" .. ngx.var.host .. uri .. "&jskey=" .. random else url = ngx.var.scheme .. "://" .. ngx.var.host .. uri .. "?jskey=" .. random end local jscode = "window.location.href='" .. url .. ';'" ngx.say(jscode)end ????????????? OpenResty + Nginx ???? Web ??????????
转载地址:http://icpfk.baihongyu.com/