Ubuntu20.04 openresty-1.21.4.2
OpenResty 是一个基于 Nginx 的 Web 应用服务器,它将 Nginx 与一组强大的 Lua 模块集成在一起,提供了高性能、可扩展和灵活的 Web 开发环境。OpenResty 的目标是通过编写简洁的 Lua 代码来构建高性能的 Web 应用,而无需额外的服务器端脚本语言。
OpenResty 提供了丰富的 Lua 库和模块,可以与各种第三方服务和数据库进行交互,如 MySQL、Redis、Memcached 等,从而实现复杂的业务逻辑和数据处理。通过 Lua 脚本的编写,您可以在请求的不同阶段对请求进行处理、路由、验证、转发等操作,以及对响应进行过滤、修改等操作。
OpenResty 的优势主要有以下几点:
总之,OpenResty 是一个功能强大且易于使用的 Web 应用服务器,它通过集成 Nginx 和 Lua,提供了一种高性能、可扩展和灵活的方式来构建 Web 应用。无论是构建 API 服务、处理静态文件、实现反向代理还是构建微服务架构,OpenResty 都是一个值得考虑的选择。
安装依赖:
apt update && apt install libpcre3-dev libssl-dev perl make build-essential curl zlib1g-dev
下载
wget https://openresty.org/download/openresty-1.21.4.2.tar.gz
解压安装编译
tar -xvf openresty-VERSION.tar.gz
cd openresty-VERSION/
./configure -j2
make -j2
sudo make install
# better also add the following line to your ~/.bashrc or ~/.bash_profile file.
export PATH=/usr/local/openresty/bin:/usr/local/openresty/nginx/sbin:$PATH
或者假如是Ubuntu可以直接根据官方文档,添加仓库,直接apt安装
下载
git clone https://github.com/unixhot/waf.git
将里面waf文件夹复制到Nginx配置文件目录
cp -rf waf /usr/local/openresty/nginx/conf/
ln -s /usr/local/openresty/lualib/resty/ /usr/local/openresty/nginx/conf/waf/resty
修改nginx配置文件nginx.conf
# WAF
lua_shared_dict limit 50m;
lua_package_path "/usr/local/openresty/nginx/conf/waf/?.lua";
init_by_lua_file "/usr/local/openresty/nginx/conf/waf/init.lua";
access_by_lua_file "/usr/local/openresty/nginx/conf/waf/access.lua";
这段 nginx 配置主要是实现使用 OpenResty 的 WAF (Web Application Firewall) 应用。具体含义如下:
Nginx+Lua WAF很重要的一个基础功能,即反向代理功能
一般通过Location里面添加 proxy_pass来实现
这里我本地实验,就不用反向代理了
proxy_pass https://www.XXX.com/;
WAF得配置在config.lua中
从access.lua可以看出检测的顺序
require 'init'
function waf_main()
if white_ip_check() then
elseif black_ip_check() then
elseif user_agent_attack_check() then
elseif cc_attack_check() then
elseif cookie_attack_check() then
elseif white_url_check() then
elseif url_attack_check() then
elseif url_args_attack_check() then
--elseif post_attack_check() then
else
return
end
end
waf_main()
规则在rule-config目录
root@vm:/usr/local/openresty/nginx/conf/waf# ls rule-config/
args.rule cookie.rule url.rule whiteip.rule
blackip.rule post.rule useragent.rule whiteurl.rule
查看url.rule得内容
root@vm:/usr/local/openresty/nginx/conf/waf/rule-config# cat url.rule
\.(htaccess|bash_history)
\.(bak|inc|old|mdb|sql|backup|java|class|tgz|gz|tar|zip)$
(phpmyadmin|jmx-console|admin-console|jmxinvokerservlet)
java\.lang
\.svn\/
/(attachments|upimg|images|css|uploadfiles|html|uploads|templets|static|template|data|inc|forumdata|upload|includes|cache|avatar)/(\\w+).(php|jsp)
可以看到一条规则一行
都是一些敏感文件,敏感后缀,敏感目录等
输入openresty启动nginx(其实是nginx得软连接)
root@vm:~# ll /usr/local/openresty/bin/openresty
lrwxrwxrwx 1 root root 37 Oct 5 01:57 /usr/local/openresty/bin/openresty -> /usr/local/openresty/nginx/sbin/nginx*
在浏览器输入zip后缀
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有