目录html
简介:利用OpenResty+unixhot自建WAF系统nginx
OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建可以处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。
OpenResty经过汇聚各类设计精良的 Nginx 模块(主要由 OpenResty 团队自主开发),从而将 Nginx 有效地变成一个强大的通用 Web 应用平台。这样,Web 开发人员和系统工程师能够使用 Lua 脚本语言调动 Nginx 支持的各类 C 以及 Lua 模块,快速构造出足以胜任 10K 乃至 1000K 以上单机并发链接的高性能 Web 应用系统。
OpenResty的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不单单对 HTTP 客户端请求,甚至于对远程后端诸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都进行一致的高性能响应。git
以CentOS7.5为例
1.安装命令以下github
yum install yum-utils -y yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo yum install openresty-resty -y yum --disablerepo="*" --enablerepo="openresty" list available #列出全部 openresty 仓库里的软件包
安装完成以下图所示
2.查看openresty所在目录web
whereis openresty
cd /usr/local/openresty/nginx/conf ls mv nginx.conf nginx.conf.$(date +%Y%m%d) #将nginx.conf移入nginx.conf.$(date +%Y%m%d)
vim nginx.conf #此时为新建 nginx.conf
将如下内容复制到nginx.conf中并保存vim
worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { server { listen 8080; location / { default_type text/html; content_by_lua ' ngx.say("<p>hello, world</p>") '; } } }
添加环境变量后端
echo "export PATH=$PATH:/usr/local/openresty/nginx/sbin" >> /etc/profile source /etc/profile
启动Openrestycentos
nginx -c /usr/local/openresty/nginx/conf/nginx.conf
查看服务并发
ps -ef | grep nginx
访问web服务验证是否正常curl
curl http://localhost:8080/
重启web服务
nginx -s reload
unixhot下载,若是没有git,先安装一下
yum -y install git git clone https://github.com/unixhot/waf.git
将WAF配置文件夹复制到nginx的配置下
cp -a ~/waf/waf /usr/local/openresty/nginx/conf/
修改nginx.conf配置,加入以下代码并保存
#WAF lua_shared_dict limit 10m; 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.conf文件以下图所示:
测试配置
/usr/local/openresty/nginx/sbin/nginx -t
从新加载配置
/usr/local/openresty/nginx/sbin/nginx -s reload
模拟SQL注入