a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 學院 > 操作系統 > 正文

Openresty+Lua+Memcached反爬蟲策略

2024-06-28 16:00:27
字體:
來源:轉載
供稿:網友

http://www.07net01.com/2015/04/822090.html

直接用Openresty替換掉了Nginx,通過Nginx內嵌Lua配合一個Memcached實現一個不依賴后端反爬蟲驗證(類似于CloudFlare的驗證碼。Memcached中包含鍵值identify_ip的用戶都會被重定向到identify.php進行處理,可以在identify.php通過驗證碼或者js進行human驗證,驗證之后將identify_IP刪除,該IP即可繼續訪問。

server {          #...        location / {            index index.php;        }        location ~ /.php$ {            content_by_lua '                uri = ngx.var.uri                if uri == "/identify.php" then                    ngx.exec("@bypass")                    return                end                clientIP = ngx.var.remote_addr                local memcached = require "resty.memcached"                local memc, err = memcached:new()                if not memc then                    ngx.say("failed to instantiate memc: ", err)                    return                end                local ok, err = memc:connect("127.0.0.1", 11211)                if not ok then                    ngx.say("failed to connect: ", err)                    return                end                local res, flags, err = memc:get("identify_"..clientIP)                if err then                    ngx.exec("@bypass")                    return                end                if  res == "1" then                    ngx.exec("@identify")                    return                end                ngx.exec("@bypass")            ';        }        location @bypass {            #echo 'bypass';            #rewrite break            fastcgi_pass unix:/var/run/php5-fpm.sock;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            include        fastcgi_params;        }        location @identify {            #echo 'identify';            #identify.php            rewrite ^/(.*)$ /identify.php?url=$request_uri redirect;       #redirect        }        location ~ //.ht {            deny  all;        }    }

identify_IP鍵值可通過分析Nginx日志自動set,通過AWK篩選出10分鐘的訪問日志。

tac chd_access.log | awk 'BEGIN{ "date -d /"-10 minute/" +/"%H:%M:%S/"" | getline min5 } { if (substr($4, 14) > min5) PRint; else exit;}' | tac

然后寫個python cron分析,比如10分鐘內請求頁面數超過100的用戶,然后插入Memcached好了...

原文地址:Openresty+Lua+Memcached反爬蟲策略, 感謝原作者分享。關鍵詞:


上一篇:input子系統

下一篇:tfs管理命令

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 成人欧美一区二区三区在线湿哒哒 | 精品www | 91精品国产麻豆 | 亚洲香蕉视频 | 色吊丝2288sds中文字幕 | 能看的黄色网址 | 国产日韩中文字幕 | 九九热精品免费视频 | 成人免费视频网站在线观看 | 国产综合亚洲精品一区二 | 在线色网| 欧美视频区 | 欧美精品一区二区三区四区 | 亚洲免费视频一区二区 | 99精品在线免费 | 九九热精品视频 | 亚洲天堂一区 | 毛片网子 | 亚洲视频手机在线观看 | 国产精品久久综合 | 欧美日本在线 | 日本天天操 | 欧美一级特 | 欧美精品福利视频 | 精品视频在线免费观看 | 日韩avav| 久久精品亚洲 | 免费看a | 国产成人精品亚洲日本在线桃色 | 亚洲精品一区中文字幕乱码 | 日韩中文字 | 日韩欧美一区二区三区视频 | 狠狠躁夜夜躁人人爽天天高潮 | 中文字幕日韩专区 | 麻豆国产一区二区三区四区 | 国产精品亚洲一区 | 久久精品高清视频 | 日韩91| 久草新 | 亚洲天堂久久 | 国产色在线观看 |