1. 使用LuaOpenResty搭建验证码服务器
  2. 雨客 2016-04-08 16:38:11 浏览2525 评论0
  3. 云数据库Redis
  4.  
  5. 摘要: Lua下有个Lua-GD图形库,通过简单的Lua语句就能控制、生成图片。 环境说明: 操作系统:RHEL6.4 RHEL系统默认已安装RPM包的Lua-5.1.4,但其只具有Lua基本功能,不提供 lua.h 等,但 Lua-GD 编译需要用到 lua.h,故 Lua 需要编译安装。 Lua-GD...
  6.  
  7. Lua下有个Lua-GD图形库,通过简单的Lua语句就能控制、生成图片。
  8.  
  9. 环境说明:
  10.  
  11. 操作系统:RHEL6.4
  12. RHEL系统默认已安装RPM包的Lua-5.1.4,但其只具有Lua基本功能,不提供 lua.h 等,但 Lua-GD 编译需要用到 lua.h,故 Lua 需要编译安装。
  13. Lua-GD 版本号格式为X.Y.XrW,其中X.Y.Z代表gd版本,W代表效力版本,所以 lua-gd 版本:lua-gd-2.0.33r2 相对应 gd 版本为:gd-2.0.33,须注意保持一致。
  14. 因生成giflua脚本中用到md5加密,故需编译安装md5
  15. 因为生成图片需要唯一命名,故依赖 UUID
  16. 另外:
  17.  
  18. 以下操作均以root用户运行,并且以下脚本的当前目录为/opt,即所有的下载的文件都会保存在/opt目录下。
  19.  
  20. 需要安装的软件如下:
  21.  
  22. OpenRestyWEB应用服务器,部署lua代码,提供URL供用户调用和访问
  23. LuaJITLUA代码解释器,使用OpenResty中集成的版本
  24. GD库:C图形库
  25. Lua-GD库:Lua绑定的C图形库,使得lua可调用gd
  26. Lua-Resty-UUID库:用于生成UUID,保证图片命名唯一性
  27. LuaSocketlua socket
  28. 安装lua
  29. 安装编译所需软件包:
  30.  
  31. $ yum install -y make gcc
  32. 下载并编译安装 lua-5.1
  33.  
  34. $ yum install -y readline-devel
  35. $ wget http://www.lua.org/ftp/lua-5.1.4.tar.gz
  36. $ tar lua-5.1.4.tar.gz
  37. $ cd lua-5.1.4
  38. $ make linux
  39. $ make linux install
  40. 安装 gd
  41. GD版本:gd-2.0.33
  42.  
  43. 下载地址: http://www.boutell.com/gd/http/gd-2.0.33.tar.gz
  44.  
  45. $ yum install -y libjpeg-devel libpng-devel freetype-devel fontconfig-devel libXpm-devel
  46.  
  47. $ wget http://www.boutell.com/gd/http/gd-2.0.33.tar.gz
  48. $ tar zvxf gd-2.0.33.tar.gz
  49. $ cd gd-2.0.33
  50. $ ./configure
  51. $ make && make install
  52. 安装 Lua-gd
  53. Lua-GD版本:lua-gd-2.0.33r2
  54.  
  55. 下载地址: http://jaist.dl.sourceforge.net/project/lua-gd/lua-gd/lua-gd-2.0.33r2%20%28for%20Lua%205.1%29/lua-gd-2.0.33r2.tar.gz
  56.  
  57. 开发手册可参考: http://ittner.github.io/lua-gd/manual.html
  58.  
  59. 说明:
  60.  
  61. 须先完成gd的安装,且版本号必须为gd-2.0.33 调用Lua-GD库的lua代码须由OpenResty中集成的LuaJIT解释执行
  62. $ wget http://sourceforge.net/projects/lua-gd/files/lua-gd/lua-gd-2.0.33r2%20(for%20Lua%205.1)/lua-gd-2.0.33r2.tar.gz/download?use_mirror=jaist
  63. $ tar zvxf lua-gd-2.0.33r2.tar.gz
  64. $ cd lua-gd-2.0.33r2
  65. 接写来修改Makefile文件:
  66.  
  67. 注释第3642
  68. 打开第4852行注释,并做如下修改
  69. OUTFILE=gd.so
  70. CFLAGS=-Wall `gdlib-config --cflags` -I/usr/local/include/lua -O3 //第49行,修改 lua 的 C 库头文件所在路径
  71. GDFEATURES=`gdlib-config --features |sed -e "s/GD_/-DGD_/g"`
  72. LFLAGS=-shared `gdlib-config --ldflags` `gdlib-config --libs` -llua -lgd //第51行,取消lua库版本号51
  73. INSTALL_PATH=/usr/local/lib/lua/5.1 //第52行,设置 gd.so 的安装路径
  74.  
  75. $(CC) -fPIC -o ... //第70行,gcc 编译,添加 -fPIC 参数
  76. 然后编译:
  77.  
  78. $ make && make install
  79. 安装 md5
  80. $ yum install unzip
  81.  
  82. $ wget https://github.com/keplerproject/md5/archive/master.zip -O md5-master.zip
  83. $ unzip md5-master.zip
  84. $ cd md5-master
  85. $ make && make install
  86. 安装 Lua-resty-UUID
  87. 调用系统的UUID模块生成的由3216进制(0-f)数组成的的串,本模块进一步压缩为62进制。正如你所想,生成的UUID越长,理论冲突率就越小,请根据业务需要自行斟酌。 基本思想为把系统生成的16字节(128bit)的UUID转换为62进制(a-zA-Z0-9),同时根据业务需要进行截断。
  88.  
  89. 下载地址: https://github.com/dcshi/lua-resty-UUID/archive/master.zip
  90.  
  91. $ yum -y install libuuid-devel
  92. $ wget https://github.com/dcshi/lua-resty-UUID/archive/master.zip -O lua-resty-UUID-master.zip
  93. $ unzip lua-resty-UUID-master.zip
  94. $ cd lua-resty-UUID-master/clib
  95. $ make
  96. 下载nginx sysguard模块
  97. 如果nginx被攻击或者访问量突然变大,nginx会因为负载变高或者内存不够用导致服务器宕机,最终导致站点无法访问。 今天要谈到的解决方法来自淘宝开发的模块nginx-http-sysguard,主要用于当负载和内存达到一定的阀值之时,会执行相应的动作,比如直接返回503,504或者其他的。一直等到内存或者负载回到阀值的范围内,站点恢复可用。简单的说,这几个模块是让nginx有个缓冲时间,缓缓。
  98. $ wget https://github.com/alibaba/nginx-http-sysguard/archive/master.zip -O nginx-http-sysguard-master.zip
  99. $ unzip nginx-http-sysguard-master.zip
  100. 安装 OpenResty
  101. OpenResty(也称为 ngx_openresty)是一个全功能的 Web 应用服务器。它打包了标准的 Nginx 核心,很多的常用的第三方模块,以及它们的大多数依赖项。 OpenResty 中的 LuaJIT 组件默认未激活,需使用 --with-luajit 选项在编译 OpenResty 时激活,使用--add-module,添加上sysguard模块
  102. 安装的版本:1.2.7.6
  103.  
  104. 下载地址:
  105.  
  106. http://openresty.org/#Download
  107. http://openresty.org/download/ngx_openresty-1.2.7.6.tar.gz
  108. 先安装依赖软件,然后在编译代码,编译时使用--perfix选项指定 OpenResty 的安装目录,--with-luajit 选项激活 LuaJIT 组件。
  109.  
  110. $ yum -y install gcc make gmake openssl-devel pcre-devel readline-devel zlib-devel
  111.  
  112. $ wget http://openresty.org/download/ngx_openresty-1.2.7.6.tar.gz
  113. $ tar zvxf ngx_openresty-1.2.7.6.tar.gz
  114. $ cd ngx_openresty-1.2.7.6
  115. $ ./configure --with-luajit --with-http_stub_status_module --add-module=/opt/nginx-http-sysguard-master/
  116. $ gmake && gmake install
  117. 创建软连接:
  118.  
  119. $ ln -s /usr/local/openresty/nginx/sbin/nginx /usr/sbin/nginx
  120. 安装 Redis Server
  121. Lua 脚本功能是 Reids 2.6 版本的最大亮点, 通过内嵌对 Lua 环境的支持, Redis 解决了长久以来不能高效地处理 CAS check-and-set)命令的缺点, 并且可以通过组合使用多个命令, 轻松实现以前很难实现或者不能高效实现的模式。
  122. $ wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz
  123. $ tar zvxf redis-2.6.14.tar.gz
  124. $ cd redis-2.6.14
  125. $ make && make install
  126.  
  127. $ mkdir -p /usr/local/redis/conf
  128. $ cp redis.conf /usr/local/redis/conf/
  129. 安装 LuaSocket
  130. LuaSocket是一个Lua扩展库,它能很方便地提供SMTPHTTPFTP等网络议访问操作。
  131. LuaSocket版本:luasocket-2.0-beta2
  132.  
  133. 下载地址: http://files.luaforge.net/releases/luasocket/luasocket/luasocket-2.0-beta2/luasocket-2.0-beta2.tar.gz
  134.  
  135. $ wget http://files.luaforge.net/releases/luasocket/luasocket/luasocket-2.0.2/luasocket-2.0.2.tar.gz
  136. $ tar zvxf luasocket-2.0.2.tar.gz
  137. $ cd luasocket-2.0.2
  138. $ make -f makefile.Linux
  139. 安装 redis-lua
  140. Redis-Lua版本:2.0
  141.  
  142. 下载地址: https://github.com/nrk/redis-lua/archive/version-2.0.zip
  143.  
  144. $ wget https://github.com/nrk/redis-lua/archive/version-2.0.zip
  145. $ unzip redis-lua-version-2.0.zip
  146. $ cd redis-lua-version-2.0
  147. 然后,拷贝redis.lua至所需目录。
  148.  
  149. lua调用方式如下:
  150.  
  151. local redis = require(“redis”)
  152. 安装 zklua
  153. zklua 仅依赖 zookeeper c API 实现,一般存在于 zookeeper-X.Y.Z/src/c 因此你需要首先安装 zookeeper c API
  154. zookeeper c API 安装:
  155.  
  156. $ wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.5/
  157. $ tar zvxf zookeeper-3.4.5
  158. $ cd zookeeper-3.4.5/src/c
  159. $ ./configure
  160. $ make && make install
  161. 然后安装zklua
  162.  
  163. $ wget https://github.com/forhappy/zklua/archive/master.zip -O zklua-master.zip
  164. $ unzip zklua-master.zip
  165. $ cd zklua-master
  166. $ make && make install
  167. 修改配置文件
  168. 配置openresty
  169.  
  170. openresty安装在/usr/local/openresty目录,在其目录下创建lualib,用于存放上面安装的一些动态连接库
  171.  
  172. mkdir -p /usr/local/openresty/lualib/captcha
  173. cp lua-resty-UUID-master/clib/libuuidx.so /usr/local/openresty/lualib/captcha/ #拷贝uuid的库文件
  174. cp -r lua-resty-UUID-master/lib/* /usr/local/openresty/lualib/captcha/
  175.  
  176. cp luasocket-2.0.2/luasocket.so.2.0 /usr/local/openresty/lualib/captcha/ #拷贝luasocket的库文件到/usr/local/openresty/lualib/captcha/
  177. ln -s /usr/local/openresty/lualib/captcha/luasocket.so.2.0 /usr/local/openresty/lualib/captcha/socket.so
  178.  
  179. cp redis-lua-version-2.0/src/redis.lua /usr/local/openresty/lualib/captcha/ #拷贝reis.lua到/usr/local/openresty/lualib/captcha/
  180.  
  181. mkdir -p /usr/local/openresty/lualib/zklua #拷贝zklua文件到/usr/local/openresty/lualib/captcha/
  182. cp cd zklua-master/zklua.so /usr/local/openresty/lualib/zklua/
  183. 配置nginx
  184.  
  185. 创建www用户:
  186.  
  187. useradd -M -s /sbin/nologin www
  188. 编辑ngnix.conf,内容如下:
  189.  
  190. user www;
  191. worker_processes 31;
  192. error_log logs/error.log;
  193. pid logs/nginx.pid;
  194. worker_rlimit_nofile 65535;
  195. events {
  196. worker_connections 1024;
  197. use epoll;
  198. }
  199.  
  200. http {
  201. include mime.types;
  202. default_type application/octet-stream;
  203. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  204. '$status $body_bytes_sent "$http_referer" '
  205. '"$http_user_agent" "$http_x_forwarded_for"';
  206. access_log logs/access.log main;
  207. sendfile on;
  208. tcp_nopush on;
  209. tcp_nodelay on;
  210. keepalive_timeout 65;
  211. gzip on;
  212. gzip_min_length 1K;
  213. gzip_buffers 4 8k;
  214. gzip_comp_level 2;
  215. gzip_types text/plain image/gif image/png image/jpg application/x-javascript text/css application/xml text/javascript;
  216. gzip_vary on;
  217.  
  218. upstream redis-pool{
  219. server 127.0.0.1:10005;
  220. keepalive 1024;
  221. }
  222.  
  223. server {
  224. sysguard on;
  225. sysguard_load load=90 action=/50x.html;
  226. server_tokens off;
  227. listen 10002;
  228. server_name localhost;
  229. charset utf-8;
  230.  
  231. location / {
  232. root html;
  233. index index.html index.htm;
  234. }
  235.  
  236. #-----------------------------------------------------------------------------------------
  237.  
  238. # 验证码生成
  239. location /captcha {
  240. set $percent 0;
  241. set $modecount 1;
  242. content_by_lua_file /usr/local/openresty/nginx/luascripts/luajit/captcha.lua;
  243. }
  244.  
  245. #-----------------------------------------------------------------------------------------
  246.  
  247. # 验证码校验
  248. location /captcha-check {
  249. content_by_lua_file /usr/local/openresty/nginx/luascripts/luajit/captcha-check.lua;
  250. }
  251.  
  252. # 验证码删除
  253. location /captcha-delete {
  254. content_by_lua_file /usr/local/openresty/nginx/luascripts/luajit/captcha-delete.lua;
  255. }
  256.  
  257. #-----------------------------------------------------------------------------------------
  258.  
  259. # 样式1-静态图片
  260. location /mode1 {
  261. content_by_lua_file /usr/local/openresty/nginx/luascripts/luajit/mode/mode1.lua;
  262. }
  263.  
  264. #-----------------------------------------------------------------------------------------
  265.  
  266. # redis中添加key-value
  267. location /redisSetQueue {
  268. internal;
  269. set_unescape_uri $key $arg_key;
  270. set_unescape_uri $val $arg_val;
  271. redis2_query rpush $key $val;
  272. redis2_pass redis-pool;
  273. }
  274. # redis中获取captcha-string
  275. location /redisGetStr {
  276. internal;
  277. set_unescape_uri $key $arg_key;
  278. redis2_query lindex $key 0;
  279. redis2_pass redis-pool;
  280. }
  281. # redis中获取captcha-image
  282. location /redisGetImg {
  283. internal;
  284. set_unescape_uri $key $arg_key;
  285. redis2_query lindex $key 1;
  286. redis2_pass redis-pool;
  287. }
  288.  
  289. #-----------------------------------------------------------------------------------------
  290.  
  291. location ~.*.(gif|jpg|png)$ {
  292. expires 10s;
  293. }
  294.  
  295. error_page 404 /404.html;
  296. error_page 500 502 503 504 /50x.html;
  297. location = /50x.html {
  298. root html;
  299. }
  300. }
  301.  
  302. }
  303. 上面将 ngnix 的端口修改为10002。
  304.  
  305. /usr/local/openresty/nginx/luascripts/luajit/captcha.lua 是用于生成验证码,内容如下:
  306.  
  307. --中控脚本
  308. --
  309. --部分应用预先生成
  310. --部分应用实时生成,并且随机选择生成样式
  311. --
  312.  
  313. ----------------------------------------------------------------------------------------------
  314. package.path = "/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/captcha/?.lua;"
  315. package.cpath = "/usr/local/openresty/lualib/?.so;/usr/local/openresty/lualib/captcha/?.so;"
  316. ----------------------------------------------------------------------------------------------
  317.  
  318. --设置随机种子
  319. local resty_uuid=require("resty.uuid")
  320. math.randomseed(tonumber(resty_uuid.gennum20()))
  321.  
  322. -----------------------------------------------------------------------------------------
  323. --
  324. --[[ 预先生成 ]]
  325. --
  326. if math.random(1,99)<tonumber(ngx.var.percent) then
  327.  
  328. --在redis的预先生成key中随机选择keyid
  329. local kid=math.random(1,ngx.var.pregencount)
  330. local res = ngx.location.capture('/redisGetImg',{ args = { key = kid } })
  331.  
  332. if res.status==200 then
  333. local parser=require("redis.parser")
  334. local pic=parser.parse_reply(res.body)
  335. ngx.header.content_type="application/octet-stream"
  336.  
  337. --在header中返回用于去redis中查找记录的key
  338. ngx.header.picgid=kid
  339.  
  340. --在body中返回captcha
  341. ngx.say(pic)
  342.  
  343. ngx.exit(200)
  344. end
  345. end
  346.  
  347. -----------------------------------------------------------------------------------------
  348. --
  349. --[[ 实时生成 ]]
  350. --
  351.  
  352. --随机选择captcha模式X
  353. local mode=math.random(1,ngx.var.modecount)
  354.  
  355. --调用modeX.lua,生成captcha
  356. local res = ngx.location.capture("/mode"..mode)
  357. if res.status==200 then
  358. ngx.header.content_type="application/octet-stream"
  359.  
  360. --在header中返回用于去redis中查找记录的key
  361. ngx.header.picgid=res.header.picgid
  362.  
  363. --在body中返回captcha
  364. ngx.say(res.body)
  365.  
  366. ngx.exit(200)
  367. end
  368. /usr/local/openresty/nginx/luascripts/luajit/captcha-check.lua 用于校验验证码:
  369.  
  370. --[[captcha check]]
  371.  
  372. ----------------------------------------------------------------------------------------------
  373. package.path = "/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/captcha/?.lua;"
  374. package.cpath = "/usr/local/openresty/lualib/?.so;/usr/local/openresty/lualib/captcha/?.so;"
  375. ----------------------------------------------------------------------------------------------
  376.  
  377. --获取请求中参数
  378. local uriargs = ngx.req.get_uri_args()
  379. local picgid = uriargs["image"]
  380. local ustr=string.lower(uriargs["str"])
  381.  
  382. --查找redis中key为picgid的记录
  383. local res = ngx.location.capture('/redisGetStr',{ args = { key = picgid } })
  384. if res.status==200 then
  385. local parser=require("redis.parser")
  386. local reply=parser.parse_reply(res.body)
  387. local rstr=string.lower(reply)
  388.  
  389. --匹配用户输入字符串与redis中记录的字符串,一致返回True,否则返回False
  390. ngx.header.content_type="text/plain"
  391. if ustr == rstr then
  392. ngx.say("True")
  393. else
  394. ngx.say("False")
  395. end
  396.  
  397. --匹配操作后删除redis中该key记录
  398. local redis = require('redis')
  399. local client = redis.connect('127.0.0.1', 10005)
  400. client:del(picgid)
  401. end
  402. /usr/local/openresty/nginx/luascripts/luajit/mode/mode1.lua 是生成静态验证码图片:
  403.  
  404. --静态图片
  405.  
  406. ------------------------------------------------------------------------------------------------
  407. package.path = "/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/captcha/?.lua;"
  408. package.cpath = "/usr/local/openresty/lualib/?.so;/usr/local/openresty/lualib/captcha/?.so;"
  409. ------------------------------------------------------------------------------------------------
  410.  
  411. --Redis中插入记录方法
  412. function setRedis(skey, sval)
  413. local res = ngx.location.capture('/redisSetQueue', {args= {key=skey,val=sval}})
  414. if res.status == 200 then
  415. return true
  416. else
  417. return false
  418. end
  419. end
  420.  
  421. --设置随机种子
  422. local resty_uuid=require("resty.uuid")
  423. math.randomseed(tonumber(resty_uuid.gennum20()))
  424.  
  425. --在32个备选字符中随机筛选4个作为captcha字符串
  426. local dict={'A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z','2','3','4','5','6','7','8','9'}
  427. local stringmark=""
  428. for i=1,4 do
  429. stringmark=stringmark..dict[math.random(1,32)]
  430. end
  431.  
  432. --图片基本info
  433. --picgid
  434. local filename= "1"..resty_uuid.gen20()..".png"
  435. --图片78x26
  436. local xsize = 78
  437. local ysize = 26
  438. --字体大小
  439. local wsize = 17.5
  440. --干扰线(yes/no)
  441. local line = "yes"
  442.  
  443. --加载模块
  444. local gd=require('gd')
  445. --创建面板
  446. local im = gd.createTrueColor(xsize, ysize)
  447. --定义颜色
  448. local black = im:colorAllocate(0, 0, 0)
  449. local grey = im:colorAllocate(202,202,202)
  450. local color={}
  451. for c=1,100 do
  452. color[c] = im:colorAllocate(math.random(100),math.random(100),math.random(100))
  453. end
  454. --画背景
  455. x, y = im:sizeXY()
  456. im:filledRectangle(0, 0, x, y, grey)
  457. --画字符
  458. gd.useFontConfig(true)
  459. for i=1,4 do
  460. k=(i-1)*16+3
  461. im:stringFT(color[math.random(100)],"Arial:bold",wsize,math.rad(math.random(-10,10)),k,22,string.sub(stringmark,i,i))
  462. end
  463. --干扰线点
  464. if line=="yes" then
  465. for j=1,math.random(3) do
  466. im:line(math.random(xsize),math.random(ysize),math.random(xsize),math.random(ysize),color[math.random(100)])
  467. end
  468. for p=1,20 do
  469. im:setPixel(math.random(xsize),math.random(ysize),color[math.random(100)])
  470. end
  471.  
  472. end
  473. --流输出
  474. local fp=im:pngStr(75)
  475.  
  476. --redis中添加picgid为key,string为value的记录
  477. setRedis(filename,stringmark)
  478.  
  479. --response header中传参picgid
  480. ngx.header.content_type="text/plain"
  481. ngx.header.picgid=filename
  482.  
  483. --页面返回pic
  484. ngx.say(fp)
  485.  
  486. --nginx退出
  487. ngx.exit(200)
  488. 配置redis
  489.  
  490. 在/usr/local/openresty/redis/conf/创建redis-10005.conf文件,内容如下:
  491.  
  492. daemonize yes
  493. pidfile /usr/local/openresty/redis/redis-10005.pid
  494. port 10005
  495. timeout 300
  496. tcp-keepalive 10
  497. loglevel notice
  498. logfile /usr/local/openresty/redis/redis-10005.log
  499. databases 16
  500. save 900 1
  501. save 300 10
  502. save 60 10000
  503. stop-writes-on-bgsave-error yes
  504. rdbcompression yes
  505. rdbchecksum yes
  506. dbfilename dump-10005.rdb
  507. dir /usr/local/openresty/redis
  508. slave-serve-stale-data yes
  509. slave-read-only yes
  510. repl-disable-tcp-nodelay no
  511. slave-priority 100
  512. appendonly no
  513. appendfsync everysec
  514. no-appendfsync-on-rewrite no
  515. auto-aof-rewrite-percentage 100
  516. auto-aof-rewrite-min-size 64mb
  517. lua-time-limit 5000
  518. slowlog-log-slower-than 10000
  519. slowlog-max-len 128
  520. hash-max-ziplist-entries 512
  521. hash-max-ziplist-value 64
  522. list-max-ziplist-entries 512
  523. list-max-ziplist-value 64
  524. set-max-intset-entries 512
  525. zset-max-ziplist-entries 128
  526. zset-max-ziplist-value 64
  527. activerehashing yes
  528. client-output-buffer-limit normal 0 0 0
  529. client-output-buffer-limit slave 256mb 64mb 60
  530. client-output-buffer-limit pubsub 32mb 8mb 60
  531. hz 10
  532. 配置验证码服务器
  533.  
  534. 在/etc/ld.so.conf.d/目录创建captcha.conf,内容如下:
  535.  
  536. $ vim /etc/ld.so.conf.d/captcha.conf
  537. /usr/local/lib
  538. /usr/local/openresty/lualib
  539. /usr/local/openresty/lualib/captcha
  540. /usr/local/openresty/lualib/zklua
  541. /usr/local/openresty/luajit/lib
  542. 测试
  543. 生成验证码
  544.  
  545. URL:http://IP:10002/captcha
  546.  
  547. 然后从响应Header中获取图片的picgid=XXXXX
  548.  
  549. 验证码校验
  550.  
  551. URL:http://IP:10002/captcha-check?image=XXXXX&str=ABCD http://IP:10002/captcha-check?image=XXXXX&str=ABCD&delete=true 或 http://IP:10002/captcha-check?image=XXXXX&str=ABCD&delete=false
  552.  
  553. 参数说明如下:
  554.  
  555. 参数image:要校验的验证码图片的picgid。
  556. 参数str:用户输入的验证码字符串。
  557. 参数delete:当且仅当传该参数且参数值为false时,校验完成之后该验证码记录不被删除,验证码未过期之前可多次校验,用于异步校验应用中;否则,若不传该参数或者其值为true,校验完成之后该验证码记录删除。
  558. 验证码删除
  559.  
  560. URL:http://IP:10002/captcha-delete?image=XXXXX
  561.  
  562. 其中image为要删除的验证码图片的picgid。
  1.  
  2. https://yq.aliyun.com/articles/25821

LUA+resty 搭建验证码服务器的更多相关文章

  1. 如何用极路由+OpenWrt+SDR电视棒搭建SDR服务器

    0×00 前言 近期因为有个从异地捕获无线信号的需求,便尝试着用OpenWrt+公网IP搭建了一台SDR服务器.如果有小伙伴嫌SDR硬件天线看起来太乱.或者电脑没有足够的USB接口也可在局域网搭建SD ...

  2. NodeMCU入门(4):搭建Web服务器,配置网络连接

    准备工作 1.NodeMCU模块 2.ESPlorer v0.2.0-rc6 3.NodeMCU-HTTP-Server 搭建web服务器 下载https://github.com/wangzexi/ ...

  3. ubuntu 14.04LTS 环境下搭建tftp服务器

    花费我一整天的时间在 ubuntu 14.04LTS 环境下搭建tftp服务器,网上好多资料参差不齐,简单来说,TFTP(Trivial File Transfer Protocol),是一个基于UD ...

  4. centos6环境下搭建irc服务器

    问题描述 有时候逛技术社区,经常会发现有个叫IRC的东西存在,想搭建下看看到底是个什么东西 说明: 操作系统环境为CentOS6.5_64 安装irc服务器 通过yum进行安装,命令如下: yum i ...

  5. 在Ubuntu Server 14.04中搭建FTP服务器(VMWare)

    自己搭建ftp服务器,方便主机与虚拟机中的Ubuntu传输文件. 选用的ftp软件为vsftpd. 1.命令行: sudo apt-get install vsftpd 2.安装完配置: vsftpd ...

  6. 如何搭建SVN服务器,详细安装步骤。

    SVN服务器端安装 下载: VisualSVN是一款图形化svn服务器.官网 http://www.visualsvn.com/server/ 下载地址: http://www.visualsvn.c ...

  7. CentOS 7搭建SVN服务器

    安装步骤如下: 1.yum install subversion 2.查看安装版本 svnserve --version 3.创建SVN版本库目录 mkdir -p /var/svn/svnrepos ...

  8. 超简单——自己搭建ftp服务器

    自己搭建ftp服务器 之所以没选择serv-u,一是因为收费,虽说网上有破解版,但是使用过程中发现破解版很不稳定,经常异常死掉,随后改选用免费的filezilla. 1软件获取 从百度搜索 FileZ ...

  9. CentOS利用postfix搭建邮件服务器

    之前我用nodemailer通过163邮箱来发送邮件,不过没过几天就一直ETIMEDOUT,不知道什么原因,想着还是自己搭一个来发邮件可能靠谱点(flag?) 安装postfix CentOS 7 自 ...

随机推荐

  1. Jquery实现textarea根据文本内容自适应高度

    本文给大家分享的是Jquery实现textarea根据文本内容自适应高度,这些在平时的项目中挺实用的,所以抽空封装了一个文本框根据输入内容自适应高度的插件,这里推荐给小伙伴们. autoTextare ...

  2. 几个有用的jQuery代码片段

    1.检测Internet Explorer版本 $(document).ready(function() { if (navigator.userAgent.match(/msie/i) ){ ale ...

  3. Error: [$rootScope:inprog] $digest already in progress

    我在 做一个 服务器分配成功以后需要更新 整个页面,我的思路是 更新成功以后,就手动的 触发一下 搜索按钮,但是在触发后,虽然成功刷新了页面,但是出现了一个 错误提示, Error: [$rootSc ...

  4. Database Schema Reader

    数据架构与INSERT脚本生成 https://dbschemareader.codeplex.com/wikipage?title=Writing%20Data&referringTitle ...

  5. Tomcat服务器原理详解

    [目录]本文主要讲解Tomcat启动和部署webapp时的原理和过程,以及其使用的配置文件的详解.主要有三大部分: 第一部分.Tomcat的简介和启动过程 第二部分.Tomcat部署webapp 第三 ...

  6. iOS 加急申请每个开发者必须会

    加急申请原来做过很多次,有成功,有拒绝(最终还是成功,一次不行,被拒绝后多来几下即可,直到成功).但是听朋友说了一件事情,很是不解:他们希望能快速审核上线,在淘宝里面找加速商店,首次上线12000元, ...

  7. elasticsearch集群管理工具head插件(转)

    elasticsearch-head是一个elasticsearch的集群管理工具,它是完全由html5编写的独立网页程序,你可以通过插件把它集成到es 插件安装方法1: 1.elasticsearc ...

  8. 通过mongodb客户端samus代码研究解决查询慢问题

    最近有项目需要用到mongodb,于是在网上下载了mongodb的源码,根据示例写了测试代码,但发现一个非常奇怪的问题:插入记录的速度比获取数据的速度还要快,而且最重要的问题是获取数据的速度无法让人接 ...

  9. hibernate4连接mysql自动创建表之错误

    我在学习Hibernate的过程中,遇到了这样一个错误:JUnit测试通过,但是数据库中却没有创建一个表,控制台的错误信息如下: HHH000388: Unsuccessful: create tab ...

  10. linux下gimp的使用

    参考资料: http://wenku.baidu.com/view/345c525f804d2b160b4ec070.html 没有视频, 只靠自己摸索使用... 参考文章: http://www.3 ...