首页 > 编程知识 正文

nginx 端口映射,反向代理负载均衡

时间:2023-05-03 11:53:41 阅读:125143 作者:4348

一、找到压缩包编译安装:

tar-zxv-fopenresty-1.15.8.1.tar.gz

cd openresty-1.15.8.1

./configure---with-Lua JIT---with-http _ stub _ status _ module-- with-pcre-- with-pcre-JIT

gmake gmake安装

二.加入nginx配置文件以测试openresty是否成功安装

服务器{

位置/赫尔洛{

default_type text/html;

content_by_lua_block {

NGX.Say(「Helloworld”

}

}

}

保存并退出,访问ip/hello,出现HelloWorld证明安装成功。

三.接下来配置WAF

在github中找到waf压缩包,解压缩/usr/local/openre sty/nginx/conf /

CP-a./waf/waf/usr/local/openre sty/nginx/conf /

也可以从github克隆waf

git clone https://github.com/UNIX hot/waf.git

CP-a./waf/waf/usr/local/openre sty/nginx/conf /

这是waf目录。/usr/local/openre sty/nginx/conf/waf

lua配置文件:/usr/local/openre sty/nginx/conf/waf/config.Lua

Waf的ip黑名单:/usr/local/openre sty/nginx/conf/waf/rule-config/black IP.rule

Waf的ip白名单:/usr/local/openre sty/nginx/conf/waf/rule-config/white IP.rule

Waf规则存储目录:/usr/local/openre sty/nginx/conf/waf/rule-config

然后修改nginx配置文件并将其添加到http中

#WAFlua_shared_dict limit 10m; Lua _ package _ path '/usr/local/openre sty/nginx/conf/waf/. Lua '; init _ by _ Lua _ file '/usr/local/openre sty/nginx/conf/waf/init.Lua '; access _ by _ Lua _ file "/usr/local/openre sty/nginx/conf/waf/access.Lua ";

保存并退出。

测试配置

/usr/local/openre sty/nginx/sbin/nginxt

重新加载配置

/usr/local/openre sty/nginx/sbin/nginx reload

WAF现在已成功配置。

WAF测试

模拟sql注入并访问ip/test.sql以确定是否发生了拦截

反向代理配置

upstream my_server {

服务器10.0.0.2:8080; (Nginx地址) keepalive 2000; }

服务器{

listen 80 (要访问的地址的端口号) server_name 10.0.0.1; (需要访问的地址) client_max_body_size 1024M; 位置/{ proxy _ pass http://my _ server/proxy _ set _ header host $ host : $ server _ port; } WAF配置文件详细说明#路径/usr/local/openre sty/nginx/conf/waf/config.Lua #详细说明,在Lua文件中,- -是注释--waf config ffig enable=disable=' off '-- waf status waf状态为config_waf_enable='on'--log dir日志的位置、json格式,视情况而定根据是否更改tmmir的情况,config _ rule _ dir='/usr/local/openre sty/nginx/conf/waf/rule-config '-enable/更改disablewhiteurl是否打开disable white ip检查白名单IP config _ white _ IP _ check=' on '-- enable/disableblockIP是否选中黑名单IP检查config _ black _ IP _ check=disable url filtering会进行URL过滤config _ URL _ check 是否打开参数检测config_URL_args_checck禁用用户代理过滤是ua检测config _ user _ agent _ check=' on '--启用disable cookie deny filtering是cookie检测config _ cookie _ check=' on '-- enable/disable CC filtering打开cc检测config _ cc _ check=' on '-- ccratethexxxofxxseconds时,每ip60秒10次config _ cc _ rate (将只能访问。disable post filtering是否会在post检测config _ post _ check=' on '-- configwafoutputredirect/html拦截中打开跳转html页面config _ waf _ output=' html '-- ifconfig _ waf _ output或setting url跳转目标地址和输出页面config _ waf _ redirection '--阻止后出现的页面config _ output _ html=[ htmlheaddml ] charset=utf-8 '/meta http-equiv=' content-language

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。