栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

【如何快速搭建企业级的WAF防火墙】

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【如何快速搭建企业级的WAF防火墙】

如何快速搭建企业级的WAF防火墙
  • 目标
    • 1. 安装 OpenResty
    • 2. 部署 Best-Nginx-Waf
        • 2.1 下载 Best-Nginx-Waf
        • 2.2 解压缩
        • 2.3 将 best-nginx-waf 文件夹复制到openresty目录下
        • 2.4 依赖包安装
    • 3. 配置 nginx.conf 启用best-nginx-waf
    • 4. 至此基于OpenResty 和 Best-Nginx-Waf搭建的WAF就可以拦截和记录攻击啦;
        • 4.1 具体项目链接

目标
	基于 Centos -7、 OpenResty、Best-Nginx-Waf  快速搭建起企业级的网站WAF防火墙; 
1. 安装 OpenResty
yum -y install  wget gcc perl unzip openssl openssl-devel
#下载并解压源码包
wget https://github.com/zylhahah/best-nginx-waf/archive/refs/heads/master.zip
tar zxf openresty-1.13.6.1.tar.gz
#编译安装
cd openresty-1.13.6.1
./configure
make
make install   #默认会安装到/usr/local/openresty目录
#openresty 自带nginx, 启动nginx
/usr/local/openresty/nginx/sbin/nginx -t  #检查配置文件语法是否正确
/usr/local/openresty/nginx/sbin/nginx     #启动nginx
2. 部署 Best-Nginx-Waf 2.1 下载 Best-Nginx-Waf
wget https://github.com/ddonline/nginx-lua-waf/archive/master.zip
2.2 解压缩
unzip master.zip  #解压后得到文件夹 best-nginx-waf
2.3 将 best-nginx-waf 文件夹复制到openresty目录下
cp -r best-nginx-waf /usr/local/openresty
2.4 依赖包安装
cd best-nginx-waf 目录下
cp http_headers.lua /usr/local/openresty/lualib/resty/
cp http.lua /usr/local/openresty/lualib/resty/

cd best-nginx-waf/luasocket-2.0.2
1、执行 make 命令
2、mkdir -p /usr/local/openresty/luajit/lib/lua/5.1/socket   
   cp src/socket.so.2.0.2 /usr/local/openresty/luajit/lib/lua/5.1/socket/core.so
   mkdir -p /usr/local/openresty/luajit/lib/lua/5.1/mime
   cp src/mime.so.1.0.2 /usr/local/openresty/luajit/lib/lua/5.1/mime/core.so
3. 配置 nginx.conf 启用best-nginx-waf
vi /usr/local/openresty/nginx/conf/nginx.conf
在http级别添加以下内容:
  lua_package_path "/usr/local/openresty/best-nginx-waf/?.lua;/usr/local/openresty/best-nginx-waf/lua-resty-redis/lib/?.lua;/usr/local/openresty/best-nginx-waf/lua-resty-lrucache/lib/?.lua;/usr/local/openresty/best-nginx-waf/luasocket-2.0.2/src/?.lua;/usr/local/openresty/lualib/?.lua;";
  lua_shared_dict limit 50m;
  lua_code_cache on;
  lua_regex_cache_max_entries 4096;
  init_worker_by_lua_file /usr/local/openresty/best-nginx-waf/job.lua;
  access_by_lua_file /usr/local/openresty/best-nginx-waf/access.lua;
  body_filter_by_lua_file /usr/local/openresty/best-nginx-waf/response_filter.lua;
    
在server级别修改server_name:
#在每个vhost中(server级别)定义server_name时,建议设置一个以上的主机名,默认第一个将做为规则中的主机区别标志,例如
  server_name  api api.test.com;
    
# 修改日志目录权限,使nginx对目录可写 具体目录位置可在conf.lua文件中修改
mkdir -p /var/log/best-nginx-waf/
chmod o+w /var/log/best-nginx-waf/
# 重载nginx使配置生效
/usr/local/openresty/nginx/sbin/nginx -t  #检查配置文件语法是否正确
/usr/local/openresty/nginx/sbin/nginx -s reload    #重载nginx
4. 至此基于OpenResty 和 Best-Nginx-Waf搭建的WAF就可以拦截和记录攻击啦; 4.1 具体项目链接

Best-Nginx-Waf: link
OpenResty: link

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/883267.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号