linux如何禁止频繁访问的ip访问nginx(IP,linux,nginx,开发技术)

时间:2024-05-03 05:37:46 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :


实验环境

版本:redhat6.5
ip:172.16.1.100,172.16.10
软件:nginx

172.16.1.10部署nginx

[root@localhosttools]#lsnginx-1.11.2.tar.gz[root@localhosttools]#yuminstallgccgcc-c++makeautomakeautoconflibtoolpcre*zlibopensslopenssl-devel[root@localhosttools]#tarxfnginx-1.11.2.tar.gz[root@localhosttools]#lsnginx-1.11.2nginx-1.11.2.tar.gz[root@localhosttools]#cdnginx-1.11.2[root@localhostnginx-1.11.2]#lsautoCHANGESCHANGES.ruconfconfigurecontribhtmlLICENSEmanREADMEsrc[root@localhostnginx-1.11.2]#./configure[root@localhostnginx-1.11.2]#make[root@localhostnginx-1.11.2]#makeinstall


测试nginx服务

[root@localhost~]#curl-I172.16.1.100HTTP/1.1200OKServer:nginx/1.11.2Date:Mon,17Aug202009:36:29GMTContent-Type:text/htmlContent-Length:15Last-Modified:Mon,17Aug202009:36:19GMTConnection:keep-aliveETag:"5f3a4f93-f"Accept-Ranges:bytes


nginx 可以正常访问。
接下来,假设172.16.1.100是黑客主机,频繁访问nginx服务

模拟172.16.1.100访问10次172.16.1.10

172.16.1.100

[root@localhost~]#ab-c1-n10http://172.16.1.10/ThisisApacheBench,Version2.3Copyright1996AdamTwiss,ZeusTechnologyLtd,http://www.zeustech.net/LicensedtoTheApacheSoftwareFoundation,http://www.apache.org/Benchmarking172.16.1.10(bepatient).....doneServerSoftware:nginx/1.11.2ServerHostname:172.16.1.10ServerPort:80DocumentPath:/DocumentLength:612bytesConcurrencyLevel:1Timetakenfortests:0.016secondsCompleterequests:10Failedrequests:0Writeerrors:0Totaltransferred:8450bytesHTMLtransferred:6120bytesRequestspersecond:617.02[#/sec](mean)Timeperrequest:1.621[ms](mean)Timeperrequest:1.621[ms](mean,acrossallconcurrentrequests)Transferrate:509.16[Kbytes/sec]receivedConnectionTimes(ms)minmean[+/-sd]medianmaxConnect:010.301Processing:110.312Waiting:010.311Total:110.512ERROR:Themedianandmeanfortheinitialconnectiontimearemorethantwicethestandarddeviationapart.TheseresultsareNOTreliable.Percentageoftherequestsservedwithinacertaintime(ms)50%166%175%180%290%295%298%299%2100%2(longestrequest)


查看nginx日志

172.16.1.10

[root@localhost~]#tail/usr/local/nginx/logs/access.log172.16.1.100--[26/Jul/2020:05:58:24+0800]"GET/HTTP/1.0"200612"-""ApacheBench/2.3"172.16.1.100--[26/Jul/2020:05:58:24+0800]"GET/HTTP/1.0"200612"-""ApacheBench/2.3"172.16.1.100--[26/Jul/2020:05:58:24+0800]"GET/HTTP/1.0"200612"-""ApacheBench/2.3"172.16.1.100--[26/Jul/2020:05:58:24+0800]"GET/HTTP/1.0"200612"-""ApacheBench/2.3"172.16.1.100--[26/Jul/2020:05:58:24+0800]"GET/HTTP/1.0"200612"-""ApacheBench/2.3"172.16.1.100--[26/Jul/2020:05:58:24+0800]"GET/HTTP/1.0"200612"-""ApacheBench/2.3"172.16.1.100--[26/Jul/2020:05:58:24+0800]"GET/HTTP/1.0"200612"-""ApacheBench/2.3"172.16.1.100--[26/Jul/2020:05:58:24+0800]"GET/HTTP/1.0"200612"-""ApacheBench/2.3"172.16.1.100--[26/Jul/2020:05:58:24+0800]"GET/HTTP/1.0"200612"-""ApacheBench/2.3"172.16.1.100--[26/Jul/2020:05:58:24+0800]"GET/HTTP/1.0"200612"-""ApacheBench/2.3"


由此可见,一秒钟之内172.16.1.100访问了nginx10次,接下来禁止掉这个问题ip

通过iptables限制ip访问

172.16.1.10

[root@localhost~]#iptables-IINPUT-s172.16.1.100-ptcp--dport80-jDROP


172.16.1.100

[root@localhost~]#curl172.16.1.10curl:(7)Failedconnectto172.16.1.10:80;连接超时


此时172.16.1.100再也不能访问nginx

nginx配置文件限制

172.16.1.10

linux如何禁止频繁访问的ip访问nginx

172.16.1.100

[root@localhost~]#curl-I172.16.1.10HTTP/1.1403ForbiddenServer:nginx/1.11.2Date:Sat,25Jul202023:12:06GMTContent-Type:text/htmlContent-Length:169Connection:keep-alive


 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:linux如何禁止频繁访问的ip访问nginx的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Linux怎么自动检测服务器停机时间下一篇:

4 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18