回答
收藏
分享
举报
各位大佬 请问nginx 如何配置waf 防火墙
提问于2022-06-14 15:17

浏览 4.4k


安装的是fastpanel 面板     新手,请勿喷 

它的nginx默认安装路径是/ect/nginx

[img]https://www.544445.xyz/images/2022/06/14/QQ20220614151311.png[/img]
[img]https://www.544445.xyz/images/2022/06/14/QQ20220614151524.png[/img]
[img]https://www.544445.xyz/images/2022/06/14/QQ20220614151553.png[/img]


请问大佬们 怎么安装 

百度学习了 搞不定  T-T


  新手,请勿喷   

请大佬指点下

已修改于2023-03-16 02:23



写下您的回答
发表回答
全部回答(1)

按点赞数排序

按时间排序

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>


<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">可能原因:您提交的内容包含危险的攻击请求


<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:1; text-indent:0px;">如何解决:


<ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">1)检查提交内容;</li>
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">2)如网站托管,请联系空间提供商;</li>
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">3)普通网站访客,请联系网站管理员;</li></ul>
</div>
</div>
</div>
</body></html>

root@ubuntu:/opt/nginx#

可以参考如下博客:
https://blog.csdn.net/m0_37814112/article/details/119967839?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-119967839-blog-106795279.pc_relevant_multi_platform_featuressortv2dupreplace&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-119967839-blog-106795279.pc_relevant_multi_platform_featuressortv2dupreplace&utm_relevant_index=2

赞同

0

回复举报

回答于2022-10-31 14:04



回复ij4905
回复
提问者
huahua882593_2283
这家伙很懒还未留下介绍~
0
文章
1
问答
0
粉丝
相关问答

第1种。参考官方文档:

“When buffering is enabled, nginx receives a response from the proxied server as soon as possible, saving it into the buffers set by the proxy_buffer_size and proxy_buffers directives. If the whole response does not fit into memory, a part of it can be saved to a temporary file on the disk. Writing to temporary files is controlled by the proxy_max_temp_file_size and proxy_temp_file_write_size directives.

When buffering is disabled, the response is passed to a client synchronously, immediately as it is received. nginx will not try to read the whole response from the proxied server. The maximum size of the data that nginx can receive from the server at a time is set by the proxy_buffer_size directive.”

点赞 0
浏览 3.3k

当遇到反向代理302错误和静态资源403错误时,可以采取几个步骤来解决问题。以下是帮助您的一般指南:

  • 了解反向代理302错误:
    • HTTP 302状态代码指示临时重定向到另一个URL。
    • 检查反向代理配置是否设置正确,包括目标URL和任何重写规则。
  • 反向代理302错误疑难解答:
    • 请确保目标服务器可访问并且响应正确。
    • 验证反向代理配置是否正确地将请求转发到相应的目标URL。
    • 检查是否有任何重写或重定向规则导致了意外行为。
    • 查看HTTP标头,查看是否有关于重定向问题的任何线索。
  • 解决反向代理302错误:
    • 调整反向代理配置以确保其正确转发请求和处理重定向。
    • 检查是否有任何服务器端脚本或应用程序正在修改HTTP响应,从而导致意外重定向。
    • 检查任何重写规则或重定向配置,并进行必要的调整。
    • 再次测试反向代理,以验证302错误是否已解决。
  • 了解静态资源403错误:
    • HTTP 403状态代码表示禁止访问错误,通常是由于权限不足或配置错误。
    • 检查请求的静态资源(例如,文件、图像、CSS、JavaScript)是否位于正确的目录中并具有必要的权限。
  • 对静态资源403错误进行疑难解答:
    • 验证服务器上的文件权限,以确保Web服务器进程具有提供静态资源所需的访问权限。
    • 检查是否有任何访问控制列表(ACL)或安全设置阻止访问静态资源。
    • 请确保所请求的静态资源存在于指定的位置,并且可以由Web服务器访问。
  • 解决静态资源403错误:
    • 调整服务器上的文件权限,以允许Web服务器进程读取静态资源。
    • 仔细检查文件的位置,必要时将其移动到正确的目录。
    • 查看可能阻止访问的任何安全设置或访问控制列表,并相应地进行修改。
    • 再次测试访问静态资源,以验证403错误是否已解决。

请记住,所提供的步骤是通用指南,实际的解决方案可能取决于特定的配置和环境。如果在完成这些步骤后仍然遇到问题,建议您查阅文档或向反向代理或Web服务器供应商寻求支持。

点赞 0
浏览 4.5k

LOG如下:偶数次是超时。

Hello and welcome!

test-->

--->


0:{"user": "demo1","age": 1}

--1->

--2: 200

--3:: [POST] test!

--5->

disconnect()

return :[POST] test!

--->


1:{"user": "demo1","age": 2}

--1->

java.net.SocketTimeoutException: Read timed out

disconnect()

return :java.net.SocketTimeoutException: Read timed out

--->


2:{"user": "demo1","age": 3}

--1->

--2: 200

--3:: [POST] test!

--5->

disconnect()

return :[POST] test!

--->


3:{"user": "demo1","age": 4}

--1->

java.net.SocketTimeoutException: Read timed out

disconnect()

return :java.net.SocketTimeoutException: Read timed out

--->


4:{"user": "demo1","age": 5}

--1->

--2: 200

--3:: [POST] test!

--5->

disconnect()

return :[POST] test!

--->


5:{"user": "demo1","age": 6}

--1->

java.net.SocketTimeoutException: Read timed out

disconnect()

return :java.net.SocketTimeoutException: Read timed out


Process finished with exit code 0


点赞 0
浏览 4.2k