t1k: Chaitin/SafeLine WAF 的 T1K 协议的 Lua 实现
安装
如果您尚未设置 RPM 仓库订阅,请 注册。然后您可以继续以下步骤。
CentOS/RHEL 7 或 Amazon Linux 2
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install lua-resty-t1k
CentOS/RHEL 8+、Fedora Linux、Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install lua5.1-resty-t1k
要在 NGINX 中使用此 Lua 库,请确保已安装 nginx-module-lua。
本文档描述了 lua-resty-t1k v1.1.6,于 2024 年 11 月 04 日发布。
概述
location / {
access_by_lua_block {
local t1k = require "resty.t1k"
local t = {
mode = "block", -- block 或 monitor 或 off,默认 off
host = "unix:/workdir/snserver.sock", -- 必需,SafeLine WAF 检测服务主机,支持 unix 域套接字、IP 或域名,字符串
port = 8000, -- 当主机为 IP 或域名时必需,SafeLine WAF 检测服务端口,整数
connect_timeout = 1000, -- 连接超时,单位为毫秒,整数,默认 1s (1000ms)
send_timeout = 1000, -- 发送超时,单位为毫秒,整数,默认 1s (1000ms)
read_timeout = 1000, -- 读取超时,单位为毫秒,整数,默认 1s (1000ms)
req_body_size = 1024, -- 请求体大小,单位为 KB,整数,默认 1MB (1024KB)
keepalive_size = 256, -- 最大并发空闲连接到 SafeLine WAF 检测服务,整数,默认 256
keepalive_timeout = 60000, -- 空闲连接超时,单位为毫秒,整数,默认 60s (60000ms)
remote_addr = "http_x_forwarded_for: 1", -- 远程地址来自 ngx.var.VARIABLE,字符串,默认来自 ngx.var.remote_addr
}
local ok, err, _ = t1k.do_access(t, true)
if not ok then
ngx.log(ngx.ERR, err)
end
}
header_filter_by_lua_block {
local t1k = require "resty.t1k"
t1k.do_header_filter()
}
}
Lua Resty T1K 与 C T1K
C T1K,作为 SafeLine 企业版的一部分,是一种用 C 语言编写的部署模式,以提高性能。 它与所有版本的 Nginx 兼容,并且不需要通过 OpenResty (lua_nginx_module) 部署。
| Lua Resty T1K | C T1K | |
|---|---|---|
| 请求检测 | ✅ | ✅ |
| 响应检测 | ❌ | ✅ |
| 健康检查* | ❌ | ✅ |
| Cookie 保护 | ❌ | ✅ |
| 机器人保护 | ❌ | ✅ |
| 代理端统计 | ❌ | ✅ |
* APISIX 实现了 chaitin-waf 插件的健康检查功能。有关更多信息,请参见 chaitin-waf 文档。
GitHub
您可以在 nginx-module-t1k 的 GitHub 仓库 中找到此模块的其他配置提示和文档。