captcha: NGINX Captcha 模块
安装
支持 CentOS/RHEL/RockyLinux 等及 Amazon Linux,并需要一个 订阅。
Fedora Linux 免费支持,无需订阅。
特定操作系统的完整安装和配置指南:
其他支持的操作系统
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install nginx-module-captcha
通过在 /etc/nginx/nginx.conf 顶部添加以下内容来启用模块:
load_module modules/ngx_http_captcha_module.so;
本文档描述了 nginx-module-captcha v0.0.1,于 2023 年 4 月 14 日发布。
示例配置:
location =/captcha {
captcha;
}
location =/login {
set_form_input $csrf_form csrf;
set_unescape_uri $csrf_unescape $csrf_form;
set_form_input $captcha_form captcha;
set_unescape_uri $captcha_unescape $captcha_form;
set_md5 $captcha_md5 "secret${captcha_unescape}${csrf_unescape}";
if ($captcha_md5 != $cookie_captcha) {
# captcha 无效代码
}
}
指令:
语法: captcha;
默认: ——
上下文: location
启用验证码图像的生成。
语法: captcha_case on | off;
默认: off
上下文: http, server, location
启用/禁用忽略验证码大小写。
语法: captcha_expire seconds;
默认: 3600
上下文: http, server, location
设置验证码过期前的秒数。
语法: captcha_height pixels;
默认: 30
上下文: http, server, location
设置验证码图像的高度。
语法: captcha_length characters;
默认: 4
上下文: http, server, location
设置验证码文本的长度。
语法: captcha_size pixels;
默认: 20
上下文: http, server, location
设置验证码字体的大小。
语法: captcha_width pixels;
默认: 130
上下文: http, server, location
设置验证码图像的宽度。
语法: captcha_charset string;
默认: abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789
上下文: http, server, location
设置验证码文本中使用的字符。
语法: captcha_csrf string;
默认: csrf
上下文: http, server, location
设置验证码的 csrf 变量名称。
语法: captcha_font string;
默认: /usr/share/fonts/ttf-liberation/LiberationSans-Regular.ttf
上下文: http, server, location
设置验证码文本的字体。
语法: captcha_name string;
默认: Captcha
上下文: http, server, location
设置验证码 cookie 的名称。
语法: captcha_secret string;
默认: secret
上下文: http, server, location
设置验证码的密钥。
GitHub
您可以在 nginx-module-captcha 的 GitHub 仓库 中找到此模块的其他配置提示和文档。