浏览 2.2k
在网上很少能找到nginx反向代理http2.0服务的配置,我看好像说nginx不能代理http2.0,只能作为http2.0的服务是对的不,谢谢
按点赞数排序
按时间排序
waf全称是Web Application Firewall,所以,能处理HTTP协议的负载均衡软件,都可以作为Waf。然而,如果性能太差,这个Waf就很容易被轻微的流量攻击打挂,而Nginx性能非常优异,因此常用于Waf。另一方面,Waf需要解析HTTP协议,包括body中的表单信息,纯粹用C语言编写工作量非常大,因此OpenResty常常是Waf的首选。
nginx可以通过ngx_lua_waf实现waf。首先需要安装luajit运行时和nginx
一、luajit运行时安装参考openresty官方:
https://github.com/openresty/lua-nginx-module#installation
我使用的如下三个版本:luajit2-2.1-20220411.tar.gz lua-nginx-module-0.10.21.tar.gz ngx_devel_kit-0.3.1.tar.gz
二、nginx安装:
我的编译参数,--prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=/home/lq/work/tongmingzhiyun/openresty/lua-nginx-module-0.10.21 --add-module=/home/lq/work/tongmingzhiyun/openresty/ngx_devel_kit-0.3.1
三、搭建waf防火墙:
参考ngx_lua_waf github仓库 readme,https://github.com/loveshell/ngx_lua_waf,需要注意的地方,
1.我的环境中其他lua包在/etc/nginx/lua/下,所以lua_package_path需要多加一个目录
lua_package_path '/opt/nginx/conf/waf/?.lua;/etc/nginx/lua/?.lua;;';
lua_shared_dict limit 10m;
init_by_lua_file /opt/nginx/conf/waf/init.lua;
access_by_lua_file /opt/nginx/conf/waf/waf.lua;
2.测试的时候不能使用127.0.0.1
curl http://127.0.0.1:80/test.php?id=../etc/passwd,防火墙args规则中白名单中有127.0.0.1,这样导致127.0.0.1的请求不会进行waf处理(这里需要注意,否则会花费大量时间排查),可以使用其他网卡地址,比如我使用ens33,
root@ubuntu:/opt/nginx# curl http://192.168.175.128:80/test.php?id=../etc/passwd
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>网站防火墙</title>
<style>
p {
line-height:20px;
}
ul{ list-style-type:none;}
li{ list-style-type:none;}
</style>
</head>
<body style=" padding:0; margin:0; font:14px/1.5 Microsoft Yahei, 宋体,sans-serif; color:#555;">
<div style="margin: 0 auto; width:1000px; padding-top:70px; overflow:hidden;">
<div style="width:600px; float:left;">
<div style=" height:40px; line-height:40px; color:#fff; font-size:16px; overflow:hidden; background:#6bb3f6; padding-left:20px;">网站防火墙 </div>
<div style="border:1px dashed #cdcece; border-top:none; font-size:14px; background:#fff; color:#555; line-height:24px; height:220px; padding:20px 20px 0 20px; overflow-y:auto;background:#f3f7f9;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600; color:#fc4f03;">您的请求带有不合法参数,已被网站管理员设置拦截!</span>