{"id":16398,"date":"2022-10-10T21:44:07","date_gmt":"2022-10-10T13:44:07","guid":{"rendered":"http:\/\/gulass.cn\/?p=16398"},"modified":"2022-10-10T21:44:31","modified_gmt":"2022-10-10T13:44:31","slug":"linux-openresty","status":"publish","type":"post","link":"https:\/\/gulass.cn\/linux-openresty.html","title":{"rendered":"OpenResty(nginx\u6269\u5c55)\u5b9e\u73b0\u9632cc\u653b\u51fb"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nOpenResty \u901a\u8fc7\u6c47\u805a\u5404\u79cd\u8bbe\u8ba1\u7cbe\u826f\u7684 Nginx \u6a21\u5757\uff08\u4e3b\u8981\u7531 OpenResty \u56e2\u961f\u81ea\u4e3b\u5f00\u53d1\uff09\uff0c\u4ece\u800c\u5c06 Nginx \u6709\u6548\u5730\u53d8\u6210\u4e00\u4e2a\u5f3a\u5927\u7684\u901a\u7528 Web \u5e94\u7528\u5e73\u53f0\u3002\u8fd9\u6837\uff0cWeb \u5f00\u53d1\u4eba\u5458\u548c\u7cfb\u7edf\u5de5\u7a0b\u5e08\u53ef\u4ee5\u4f7f\u7528 Lua \u811a\u672c\u8bed\u8a00\u8c03\u52a8 Nginx \u652f\u6301\u7684\u5404\u79cd C \u4ee5\u53ca Lua \u6a21\u5757\uff0c\u5feb\u901f\u6784\u9020\u51fa\u8db3\u4ee5\u80dc\u4efb 10K \u4e43\u81f3 1000K \u4ee5\u4e0a\u5355\u673a\u5e76\u53d1\u8fde\u63a5\u7684\u9ad8\u6027\u80fd Web \u5e94\u7528\u7cfb\u7edf<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u6d41\u7a0b\u56fe<\/strong><\/div>\n

\u672c\u6587\u4ecb\u7ecd\u4f7f\u7528openresty\u6765\u5b9e\u73b0\u9632cc\u653b\u51fb\u7684\u529f\u80fd\u3002openresty\u5b98\u7f51http:\/\/openresty.org\/cn\/index.html\u3002\u4e0b\u9762\u662f\u9632cc\u653b\u51fb\u7684\u6d41\u7a0b\u56fe\u3002
\n\u6839\u636e\u6d41\u7a0b\u56fe\uff0c\u6211\u4eec\u77e5\u9053\u9632cc\u653b\u51fb\u4e3b\u8981\u5305\u62ec\u4e24\u90e8\u5206\uff0c\u4e00\u662f\u9650\u5236\u8bf7\u6c42\u901f\u5ea6\uff0c\u4e8c\u662f\u7ed9\u7528\u6237\u53d1\u9001js\u8df3\u8f6c\u4ee3\u7801\u8fdb\u884c\u9a8c\u8bc1\u8bf7\u6c42\u662f\u5426\u5408\u6cd5\u3002
\n\"OpenResty\"<\/p>\n

\u5b89\u88c5\u4f9d\u8d56<\/strong><\/span><\/div>\n

RHEL\/Centos:<\/p>\n

yum install readline-devel pcre-devel openssl-devel\r\n<\/pre>\n

ubuntu:<\/p>\n

apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl\r\n<\/pre>\n
luajit\u5b89\u88c5<\/strong><\/span><\/div>\n
    cd \/tmp\/\r\n    git clone http:\/\/luajit.org\/git\/luajit-2.0.git\r\n    cd luajit-2.0\/\r\n    make && make install\r\n    ln -sf luajit-2.0.0-beta10 \/usr\/local\/bin\/luajit\r\n    ln -sf \/usr\/local\/lib\/libluajit-5.1.so.2 \/usr\/lib\/\r\n<\/pre>\n
openresty\u5b89\u88c5<\/strong><\/span><\/div>\n
    cd \/tmp\r\n    wget http:\/\/agentzh.org\/misc\/nginx\/ngx_openresty-1.2.4.13.tar.gz\r\n    tar xzf ngx_openresty-1.2.4.13.tar.gz\r\n    cd ngx_openresty-1.2.4.13\/\r\n    .\/configure --prefix=\/usr\/local\/openresty --with-luajit\r\n    make && make install\r\n<\/pre>\n
nginx\u914d\u7f6e<\/strong><\/span><\/div>\n

nginx.conf:<\/p>\n

    http{\r\n    [......]\r\n    lua_shared_dict limit 10m;\r\n    lua_shared_dict jsjump 10m;\r\n     \r\n        server {\r\n    #lua_code_cache off;\r\n            listen       80;\r\n            server_name  www.centos.bz;\r\n     \r\n            location \/ {\r\n    default_type  text\/html;\r\n    content_by_lua_file \"\/usr\/local\/openresty\/nginx\/conf\/lua\";\r\n            }\r\n            location @cc {\r\n                internal;\r\n                root   html;\r\n                index  index.html index.htm;\r\n            }\r\n        }\r\n    }\r\n<\/pre>\n

\/usr\/local\/openresty\/nginx\/conf\/lua\u6587\u4ef6:<\/p>\n

    local ip = ngx.var.binary_remote_addr\r\n    local limit = ngx.shared.limit\r\n    local req,_=limit:get(ip)\r\n    if req then\r\n            if req > 20 then\r\n                    ngx.exit(503)\r\n            else\r\n                    limit:incr(ip,1)\r\n            end\r\n    else\r\n            limit:set(ip,1,10)\r\n    end\r\n     \r\n    local jsjump = ngx.shared.jsjump\r\n    local uri = ngx.var.request_uri\r\n    local jspara,flags=jsjump:get(ip)\r\n    local args = ngx.req.get_uri_args()\r\n    if jspara then\r\n        if flags then\r\n            ngx.exec(\"@cc\")\r\n        else\r\n                    local p_jskey=''\r\n                    if args[\"jskey\"] and type(args[\"jskey\"])=='table' then\r\n                             p_jskey=args[\"jskey\"][table.getn(args[\"jskey\"])]\r\n                    else\r\n                             p_jskey=args[\"jskey\"]\r\n                    end\r\n            if p_jskey and p_jskey==tostring(jspara) then\r\n                            jsjump:set(ip,jspara,3600,1)\r\n                            ngx.exec(\"@cc\")\r\n            else\r\n                            local url=''\r\n                            if ngx.var.args then\r\n                                   url=ngx.var.scheme..\":\/\/\"..ngx.var.host..uri..\"&jskey=\"..jspara\r\n                            else\r\n                                   url=ngx.var.scheme..\":\/\/\"..ngx.var.host..uri..\"?jskey=\"..jspara\r\n                            end\r\n                            local jscode=\"window.location.href='\"..url..\"';\"\r\n                            ngx.say(jscode)\r\n            end\r\n        end\r\n    else\r\n    math.randomseed( os.time() );\r\n        local random=math.random(100000,999999)\r\n        jsjump:set(ip,random,60)\r\n        local url=''\r\n        if ngx.var.args then\r\n            url=ngx.var.scheme..\":\/\/\"..ngx.var.host..uri..\"&jskey=\"..random\r\n        else\r\n            url=ngx.var.scheme..\":\/\/\"..ngx.var.host..uri..\"?jskey=\"..random\r\n        end\r\n        local jscode=\"window.location.href='\"..url..\"';\"\r\n        ngx.say(jscode)\r\n    end\r\n<\/pre>\n

lua\u4ee3\u7801\u90e8\u5206\u89e3\u91ca\uff1a
\n1\u30011-12\u884c\u662f\u9650\u901f\u529f\u80fd\u5b9e\u73b0\uff0c\u7b2c5\u548c\u7b2c10\u884c\u8868\u793a10\u79d2\u949f\u5185\u5bb9\u6700\u591a\u53ea\u80fd\u8bf7\u6c4220\u6b21\u3002
\n2\u300114-48\u884c\u662f\u9a8c\u8bc1\u90e8\u5206\uff0c24\u884c\u4e2d\u76843600\u8868\u793a\u9a8c\u8bc1\u901a\u8fc7\u540e\uff0c\u767d\u540d\u5355\u65f6\u95f4\u4e3a3600\u79d2\uff0c\u53731\u5c0f\u65f6\u3002<\/p>\n

update: 2013.5.26
\n1\u3001\u4fee\u590dJS\u65e0\u9650\u8df3\u8f6cbug
\n2\u3001\u589e\u52a0\u968f\u673a\u79cd\u5b50<\/p>\n

\n

\u539f\u6587\u5730\u5740\uff1ahttps:\/\/www.centos.bz\/2012\/12\/openresty-nginx-block-cc-attack-deploy\/<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1a http:\/\/gulass.cn\/linux-openresty.html \u200e
\n<\/a>\u7f16\u8f91\uff1a\u5f90\u79ef\u6167\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb OpenResty \u901a\u8fc7\u6c47\u805a\u5404\u79cd\u8bbe\u8ba1\u7cbe\u826f\u7684 Nginx \u6a21\u5757\uff08\u4e3b\u8981\u7531 OpenResty \u56e2\u961f\u81ea\u4e3b\u5f00\u53d1\uff09 […]<\/p>\n","protected":false},"author":63,"featured_media":4896,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-16398","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/16398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=16398"}],"version-history":[{"count":8,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/16398\/revisions"}],"predecessor-version":[{"id":254566,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/16398\/revisions\/254566"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/4896"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=16398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=16398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=16398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}